Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

TreeView Tag Property

 

Hi all,

 

Been having a bit of a mare! for the last hour or so, I just cant figure out how to retrieve a value out of the treeview controls tag property. Can anyone help please.

 

What I have is...

 

Dim strSelectedNodeID As String

 

strSelectedNodeID = TreeViewAddressBook.SelectedNode.Tag

 

...however it doesn't work as I get an error of "object reference not set to an instance of an object" on the line above.

 

Cheers,

 

L.

Edited by CAVESTER
Posted

You do know what that error means, right?

 

If not one of those objects (either the string or the node.tag) is not prepared to make this exchange. (i.e not initialized, usually done in the constructor).

Look through the code see where that node is added and ensure that the tag is set to something initially, even if it means that you cycle through all the nodes (before implementing the tags) to set the tags as new objects().

e.g when creating nodes:

Node myNode = new Node();

myNode.Tag = new object();

myParentNode.Nodes.Add(myNode);

 

thats c# not sure about VB.NET, to be perfectly honest you should drop that crap, c# takes just a little more to learn and is way better.

 

If your using ASP.NET it gets more complicated and is a problem i have shared in the past and failed to overcome properly with full understanding, so dont ask me.

 

jax

Posted

an item has been selected from the treeview (the code is in the TreeViewAddressBook_Click event) and the tag does have a number in it as I can identify this when populating it via the debugger.

 

However when I try to extract the number (database record ID) back from the tag it all goes a bit wrong as I stated above. I thought it may be something to do with the tag being of type object and trying to pass it to a string but a Ctype() conversion construct makes no difference.

 

Anyone got any helpfull info on treeviews in VB.NET?

 

Cheers,

 

L.

Posted

in the debugger the SelectedNode property is stated as being "Nothing". I guess this why I am getting the error but why is it "Nothing" if I have selected it? :confused:

 

L.

Posted

Sorted it in the end guy's thanks for the input. It was because the code was inside of the click event and the treeview selection does not happen untill after the click has been made. Putting the code into the double_click event solved it. :)

 

L.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...