|
-
Feb 15th, 2003, 04:08 AM
#1
Thread Starter
Member
Please ammend this code of TreeView
Hi,
in the following code I can create a TreeView control with only one Root and only one branch. Please change or ammend this code to be able to make the branch as a root of another branch and so on.. I mean Treeview with unlimited levels.
You can suggest any new variables or objects
Do While Not rsCategories.EOF
Me.ctlTreeView.Nodes.Add , , "Cat" & rsCategories("CategoryID"), rsCategories("CategoryName") ', "category", "category"
rsCategories.MoveNext
Loop
Do While Not rsProducts.EOF
Me.ctlTreeView.Nodes.Add "Cat" & rsProducts("categoryID"), tvwChild, "Prod" & rsProducts("productid"), rsProducts("ProductName") ' "product", "product"
rsProducts.MoveNext
Loop
Thanx in advance
-
Feb 15th, 2003, 11:00 AM
#2
In order to add multiple nodes you will need to make sure that your key values are unique. Here is one way of doing it.
VB Code:
Private Sub Form_Load()
Dim strParentKey As String
On Error GoTo ErrorRoutine
TreeView1.Nodes.Add , , UniqueKey, "one"
strParentKey = TreeView1.Nodes(TreeView1.Nodes.Count).Key
TreeView1.Nodes.Add strParentKey, tvwChild, UniqueKey, "two"
TreeView1.Nodes.Add strParentKey, tvwChild, UniqueKey, "three"
TreeView1.Nodes.Add strParentKey, tvwChild, UniqueKey, "Four"
TreeView1.Nodes.Add strParentKey, tvwChild, UniqueKey, "Five"
Exit Sub
ErrorRoutine:
If Err.Number = 35602 Then
' Duplicate key, get a different one
Resume
End If
End Sub
Public Function UniqueKey() As String
UniqueKey = "K" & 1 + Int(Rnd() * 10000000)
End Function
You can also put some more info in the key like
TreeView1.Nodes.Add , , "category" & UniqueKey, "one"
-
Feb 15th, 2003, 01:47 PM
#3
Thread Starter
Member
Hi Martin
Thanx for answering. I need many steps , I mean let "Two" like a Root and branch at the same time. how can I do that
Mina
-
Feb 15th, 2003, 04:28 PM
#4
It's pretty much the same principle. You just need to refer to the parent.
VB Code:
Private Sub Form_Load()
Dim strParentKey As String
Dim strTwoKey As String
Dim strTwo_bKey As String
On Error GoTo ErrorRoutine
TreeView1.Nodes.Add , , UniqueKey, "one"
strParentKey = TreeView1.Nodes(TreeView1.Nodes.Count).Key
TreeView1.Nodes.Add strParentKey, tvwChild, UniqueKey, "two"
strTwoKey = TreeView1.Nodes(TreeView1.Nodes.Count).Key
TreeView1.Nodes.Add strTwoKey, tvwChild, UniqueKey, "two-a"
TreeView1.Nodes.Add strTwoKey, tvwChild, UniqueKey, "two-b"
strTwo_bKey = TreeView1.Nodes(TreeView1.Nodes.Count).Key
TreeView1.Nodes.Add strTwo_bKey, tvwChild, UniqueKey, "two-b-1"
TreeView1.Nodes.Add strTwoKey, tvwChild, UniqueKey, "two-c"
TreeView1.Nodes.Add strParentKey, tvwChild, UniqueKey, "three"
TreeView1.Nodes.Add strParentKey, tvwChild, UniqueKey, "Four"
TreeView1.Nodes.Add strParentKey, tvwChild, UniqueKey, "Five"
Exit Sub
ErrorRoutine:
If Err.Number = 35602 Then
' Duplicate key, get a different one
Resume
End If
End Sub
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
|