CAVESTER Posted December 4, 2003 Posted December 4, 2003 (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 December 4, 2003 by CAVESTER Quote
Administrators PlausiblyDamp Posted December 4, 2003 Administrators Posted December 4, 2003 Have you selected a node in the treeview ? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Tamu_Tamu Posted December 4, 2003 Posted December 4, 2003 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 Quote
CAVESTER Posted December 4, 2003 Author Posted December 4, 2003 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. Quote
CAVESTER Posted December 4, 2003 Author Posted December 4, 2003 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. Quote
CAVESTER Posted December 4, 2003 Author Posted December 4, 2003 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.