Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Can I Move From Parent To Child In Treeview??? 2

Status
Not open for further replies.

hneal98

Programmer
Aug 13, 2002
1,637
US
Hi I need to know if there is a way to move from the parent node in a treeview to a child node. If anyone has a code example, that would help immensely.

Thanks. :)
 
You can select the first child node of the currently selected node using:

TreeView.SelectedNode = TreeView.SelectedNode.Nodes(0)

If you need to programatically identify a node to which you want to move to, which could be anywhere in the tree, you will need a recursive function to 'find' it. See the following thread:

thread796-586727
 
Thanks SHelton, this was very helpful. I kind of knew this, but my mind went blank.

Thanks again.
 
I do have one more question. This worked great to find the first occurance of a node. The problem I am having now is, I would like to find the next occurance of string contained in the node.

For example, I have 5 nodes that contain the string "HL". The whole node might like something like this: "HL*1*21" and another might look like "HL*3*19". I have just found the 1st one, now I want to find the next one. With the current process, I keep finding the first one and it never moves to the next. Do you know how I might go about doing that?

Thanks again.
 
In my own programs I usually store a unique reference in the tag property of each node (e.g. a description and a unique ID, usually pulled from a database identity column, such as File_1034). This then allows me to use the FindNode function to search for the unique tag value.

If you are looking for the text and it always starts with 'HL', you could use the Split function to return the values:

If TreeNode.Text.StartsWith("HL") Then
Dim s() As String
s = TreeNode.Text.Split(Convert.ToChar("*"))
End If

This would produce the following values:

s(0) = "HL"
s(1) = "1"
s(2) = "21"

You could pass in the required string to the FindNode procedure and retunr the node which matches.
 
That is good, but sometimes the text is in the middle or elseware. One thing I have decided to do is store the item i found in a hashtable. that way, I can simply check to see if that node has been found previously and then just move on to the next. Then i clear the hashtable when the search criteria is changed or the application is closed.

Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top