HI idle_mind,
i tried ur method but i got 1 question here.
i set my treeview properties, checkbox = true, hide selection=true.when i run ur code, it doesn't capture the correct result.it will always capture the highlighted item in the treeview, which captured as treeview1.selected. this mean even i check on index 10, but my treeview's highlighted item will still remain on index 5, and the result .selected will return value of index 5.
it will return correct asnwer only when user purposely highlight that item, then check on the check box for the same item, which is not logic.
may b some of my properties setting is not correct, pls correct me if i m wrong.
rgds,
daniel
Main Topics
Browse All Topics





by: Idle_MindPosted on 2004-03-15 at 22:12:16ID: 10603735
Create a new project and add a TreeView control and a label.
t _ ent.Text
Personally, I think having a MsgBox on each click is a bad idea so I made the info appear in a Label instead. It's easy enough to change it to a MsgBox if you like.
All you need to do is implement the image list.
Idle_Mind
Private Sub Form_Load()
Dim nodX As Node ' Declare the object variable.
Set nodX = TreeView1.Nodes.Add(, , "A", "A")
Set nodX = TreeView1.Nodes.Add("A", tvwChild, "A1", "1")
Set nodX = TreeView1.Nodes.Add("A", tvwChild, "A2", "2")
Set nodX = TreeView1.Nodes.Add("A", tvwChild, "A3", "3")
Set nodX = TreeView1.Nodes.Add(, , "B", "B")
Set nodX = TreeView1.Nodes.Add("B", tvwChild, "B4", "4")
Set nodX = TreeView1.Nodes.Add("B", tvwChild, "B5", "5")
Set nodX = TreeView1.Nodes.Add("B", tvwChild, "B6", "6")
Set nodX = TreeView1.Nodes.Add(, , "C", "C")
Set nodX = TreeView1.Nodes.Add("C", tvwChild, "C7", "7")
Set nodX = TreeView1.Nodes.Add("C", tvwChild, "C8", "8")
Set nodX = TreeView1.Nodes.Add("C", tvwChild, "C9", "9")
Set nodX = TreeView1.Nodes.Add(, , "D", "D")
Set nodX = TreeView1.Nodes.Add("D", tvwChild, "D10", "10")
Set nodX = TreeView1.Nodes.Add("D", tvwChild, "D11", "11")
Set nodX = TreeView1.Nodes.Add("D", tvwChild, "D12", "12")
End Sub
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
Dim x As Node
If Node.Parent Is Nothing Then
For Each x In TreeView1.Nodes
If x.Parent Is Nothing And x.Key <> Node.Key Then
x.Expanded = False
End If
Next x
Node.Expanded = True
Node.Child.Selected = True
End If
Label1.Caption = "Node: " & TreeView1.SelectedItem.Tex
& " Parent Node: " & TreeView1.SelectedItem.Par
End Sub