byoung Posted January 29, 2003 Posted January 29, 2003 Anyone know of a quick to find a value in a Treeview by index or going directly to the text value? I know you can use recursive methods and loop through TreeNode collections, etc. Some code examples would be very much appreciated... Thanks! Barry Quote
*Gurus* divil Posted January 29, 2003 *Gurus* Posted January 29, 2003 You can't. The only way you could do this is by keeping a hashtable object around to associate text values with treenode objects as you add them. If this would be useful to you, I suggest looking up the Hashtable class in the help. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
bacchus Posted December 2, 2003 Posted December 2, 2003 Well, actually you can do this. I hope this might help... 'assuming treeView1 control has been added to form 'Sample XML <TREENODES><treenode text="Text to be displayed on page" NodeData="hidden data value associated to displayed text"></treenode></TREENODES> 'Load XML into treeView control static or dynamic 'Static treeView1.TreeNodeSrc = "TreeViewControl.xml" 'Dynamic Dim sMyXML as String Dim myXMLDocument as XmlDocument 'Build your XML string however you need to sMyXML = "<TREENODES><treenode text=""Text to be displayed on page"" NodeData=""hidden data value associated to displayed text""></treenode></TREENODES>" myXMLDocument.LoadXML(sMyXML) treeView1.TreeNodeSrc = myDomDocument.InnerXML treeView1.DataBind() 'Code for treeView1_SelectedIndexChange 'AutoPostBack property must be set to true for this event to fire on each node select, otherwise the events are queued dim tnSelectedNode as TreeNode tnSelectedNode = treeView1.GetNodeFromIndex(treeView1.SelectedNodeIndex) Response.write("Selected node display text: " & tnSelectedNode.Text & "<br>") Response.write("Selected node hidden value: " & tnSelectedNode.NodeData & "<br>") That should do it 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.