|
-
Jun 7th, 2019, 04:46 AM
#1
Thread Starter
New Member
Treeview fun!
Hi,
I am trying to dynamically build a multi level tree view tree for data held in an SQL database. The database holds the node name and the parent name, this allows for a flexible number of levels to be stored.
The issue I'm having is translating the level structure to the treeview component. I can recursively query the database but I can't programatically select a treenode in order to add a level.
I have tried using:
Code:
treeView1.SelectedNode=treeView1.Nodes.Find("Node1", true)
or
Code:
Dim node As TreeNode() = TreeView1.Nodes.Find("<selected word>", True)
TreeView1.SelectedNode = node(0)
and every combination of that I can find in forums but each time nothing is found so the selectednode assignment fails.
Any points would be greatly appreciated!
-
Jun 7th, 2019, 05:28 AM
#2
Thread Starter
New Member
Re: Treeview fun!
I think I might have got it.
When adding the parent node to the treeview I was only adding the text and not the key. By specifiing the and the name:
Code:
parent="Top Level"
TreeView1.Nodes.Add(parent, parent)
Code:
Dim myNodes() As TreeNode = TreeView1.Nodes.Find(parent, True)
If Not sqldatareader.Item(0) Is DBNull.Value Then
myNodes(0).Nodes.Add(sqldatareader.Item(0).ToString, sqldatareader.Item(0).ToString)
End If
This seems to now dynamically build the correct tree structure.
-
Jun 7th, 2019, 04:09 PM
#3
Re: Treeview fun!
 Originally Posted by Mattpstanding
I think I might have got it.
When adding the parent node to the treeview I was only adding the text and not the key. By specifiing the and the name:
Code:
parent="Top Level"
TreeView1.Nodes.Add(parent, parent)
Code:
Dim myNodes() As TreeNode = TreeView1.Nodes.Find(parent, True)
If Not sqldatareader.Item(0) Is DBNull.Value Then
myNodes(0).Nodes.Add(sqldatareader.Item(0).ToString, sqldatareader.Item(0).ToString)
End If
This seems to now dynamically build the correct tree structure.
You're right. That's how to do exactly what you asked. No trickery, simply a case of using a key on each node...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|