Click here to Skip to main content
16,020,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i have a treeview in windows form application when the node mousemove is raised i need to assign the the node tag text in to some authore property but it is throunig an exception any one pls help me ......
here is my code
C#
private void treeview1_MouseMove(object sender, MouseEventArgs e)
   {
   TreeNode theNode = browserControl1.trvObjects.GetNodeAt(e.X, e.Y);
   string testtext=theNode.Tag.ToString();  //Here it is thrwing an exception as Object reference not set to an instance of an object.
                                            //use new key word to create new object
   }



[edit]Code block added, "Treat my content as plain text..." option disabled - OriginalGriff[/edit]
Posted
Updated 31-Aug-11 0:55am
v2

There are two possibilities:
1) theNode is null
2) theNode.Tag is null

Put a breakpoint in your code and find out which.
If it is the former, then you need to look at your MouseMove handler, and possibly test for null and exclude it to avoid times whenteh mouse if in the TreeView, but not over a node .
If the latter, then you need to look at your Tag setting code.
 
Share this answer
 
Why don't you just debug the code to find out which value is null and then either make sure that that value is not null or put in a check (if else) for that null object.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900