Filling treeview

  • Thread starter Thread starter Andreas Schubert
  • Start date Start date
A

Andreas Schubert

Hello newsgroup,

If this should be the wrong group for my questions, I apologize.
I am a newbie to .NET and try to achive the following:
A Treeview should be filled with nodes from a database. The table has this
structure:

Node_id NodeText ParentNode

The number of nodes and levels is not limited.
Can someone give me an example on how to fill the treeview with this data?

Thanks for your help

Andreas
 
ok, the samples are good to understand.
Where I have a problem is how to generate the dataset.
with this table layout

Node_id NodeText ParentNode_ID

what SQL statement would I use?
something like : Select Node_id, NodeText, ParentNode_ID FROM tbl_Nodes
Order By ParentNode_ID?
 
Hi!

I'm also interested about filling treeview of the DataTable. This
example looks much better and easier how I have done filling before, and
now I'd like to change my code for this simplier way of filling.

My problem is how to make SQL query correctly (ORDER BY...?), my SQL is
about...

SELECT NodeID, NodeLevel, ParentID, NodeText FROM myTable

(NodeID, NodeLevel, and ParentID fields are numeric)

....and because the number of nodes and levels is not limited in my case
too, how to change code below (piece of of microsoft code sample) to
make it fill treeview levels as much as needed?

' Add a root TreeNode for each Customer object in the ArrayList.
Dim customer2 As Customer
For Each customer2 In customerArray
treeView1.Nodes.Add(New TreeNode(customer2.CustomerName))

' Add a child TreeNode for each Order object in the current Customer
object.
Dim order1 As Order
For Each order1 In customer2.CustomerOrders
treeView1.Nodes(customerArray.IndexOf(customer2)).Nodes.Add( _
New TreeNode(customer2.CustomerName + "." + order1.OrderID))
Next order1
Next customer2

after changing it like...

For Each dr As DataRow In dt.Rows
trv.Nodes.Add(New TreeNode(dr("NodeText").ToString()))
....
 
Hi!

I'm also interested about filling treeview of the DataTable. This
example looks much better and easier how I have done filling before, and
now I'd like to change my code for this simplier way of filling.

My problem is how to make SQL query correctly (ORDER BY...?), my SQL is
about...

SELECT NodeID, NodeLevel, ParentID, NodeText FROM myTable

(NodeID, NodeLevel, and ParentID fields are numeric)

....and because the number of nodes and levels is not limited in my case
too, how to change code below (piece of of microsoft code sample) to
make it fill treeview levels as much as needed?

' Add a root TreeNode for each Customer object in the ArrayList.
Dim customer2 As Customer
For Each customer2 In customerArray
treeView1.Nodes.Add(New TreeNode(customer2.CustomerName))

' Add a child TreeNode for each Order object in the current Customer
object.
Dim order1 As Order
For Each order1 In customer2.CustomerOrders
treeView1.Nodes(customerArray.IndexOf(customer2)).Nodes.Add( _
New TreeNode(customer2.CustomerName + "." + order1.OrderID))
Next order1
Next customer2

after changing it like...

For Each dr As DataRow In dt.Rows
trv.Nodes.Add(New TreeNode(dr("NodeText").ToString()))
....
 
Back
Top