Click to See Complete Forum and Search --> : treeview control
szd
May 17th, 2001, 01:49 PM
HI,
Is it possible to create a treeview dynamically on run time? The data to
create the treeview comes from a database and can differ from user to user.
Thanks in advance.
Andrew_Fryer
May 17th, 2001, 02:12 PM
If yuo place the blank object on the form that you require then the branches can be created dynamically depending on the data to be displayed
Johnny101
May 17th, 2001, 02:12 PM
sure is - you just have to some data to put in there. Hopefully, you're data will be user specific and have some sort of hierarchical structure that can be easily represented in the tree view control.
Look into adding things from a recordset first, then start dealing with the recursion - which will be required to build the tree correctly.
it's pretty easy, once you get used to the routines.
john
John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org
szd
May 17th, 2001, 02:23 PM
Thanks for your help.
Do you know where I could find some sample code that shows me how to create the treeview during run time?
Johnny101
May 17th, 2001, 04:07 PM
Here's a very simple example:
Dim i as Integer
Dim nod as Node
Dim nod2 as Node
TreeView1.Style = tvwTreelinesPlusMinusText
TreeView1.LineStyle = tvwRootLines
for i = 1 to 10
set nod = TreeView1.Nodes.Add(, , , i & "Parent")
for j = 1 to 3
set nod2 = TreeView1.Nodes.Add(nod.Index, tvwChild, , "Child" & j)
for x = 1 to 2
TreeView1.Nodes.Add nod2.Index, tvwChild, , x & " grandchild"
next x
next j
next i
this will add some nodes and some child nodes and then some grandchildren nodes to a treeview named TreeView1.
You can use this as a guide to populating the treeview from a recordset. if you have questions, post them here and someone will help you.
hope this helps,
john
John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.