Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Gurus*
Posted
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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

  • 10 months later...
Posted

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

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...