PDA

View Full Version : Checkboxes in a Treeview



Sowanso
09-04-2006, 06:52 AM
Hello,
do you have any code which supports better functionality of treeview checkboxes? Actually I mean if I check checkbox in a parent node, I expect all child nodes to check automatically. I expect the same of unchecking the checkbox. I started with following, but I can imagine a better solution not going through all nodes, but only for TreeView1.Nodes.Item(i).Children - unfortunately I cannot make it work.

Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)
Dim i As Integer
If (Node.Checked = True) Then
For i = 2 To TreeView1.Nodes.Count
If (TreeView1.Nodes.Item(i).Parent.Checked = True) Then TreeView1.Nodes.Item(i).Checked = True
Next i
Else
For i = 2 To TreeView1.Nodes.Count
If (TreeView1.Nodes.Item(i).Parent = Node) Then
TreeView1.Nodes.Item(i).Checked = False
Call TreeView1_NodeCheck(TreeView1.Nodes.Item(i))
End If
Next i
End If
End Sub

Edit 9/5/20006 Code updated..

Any Ideas?