TreeView.Nodes.ContainsKey does not look thru all levels??

  • Thread starter Thread starter Josef Brzobohaty
  • Start date Start date
J

Josef Brzobohaty

Guest
Hi,

I am confused. Does .containskey look thru all treenode collection?

When I have code witch should reload from data table previously saved Treeview nodes and I use command .containskey to make sure that parent is there. I end up by getting false even the parent with specific name is there. When I run it without checking on parent (in future use it might end up by runtime) it works with use of nodes.find.

But I want to make sure. Do I have to create Function to loop thru all nodes (in future it might be big structure) or is there a way to check if exist or not.

Thanks.


Here is code where I commented out not working .caontainskey command

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.TreeView2.Nodes.Clear()
Dim dt As DataTable = DsUsers.dtUsers
Dim new_node As TreeNode
'Dim no() As TreeNode

For Each r As DataRow In dt.Rows
If r.Item("NodeLevel").ToString = 0 Then
new_node = New TreeNode(r.Item("NodeID").ToString)
new_node.Name = r.Item("NodeID").ToString
new_node.Text = r.Item("NodeText").ToString
new_node.ImageIndex = r.Item("NodeImageIndex").ToString
new_node.SelectedImageIndex = r.Item("NodeImageindexSelected").ToString
If Not r.Item("NodeText2") Is Nothing Then new_node.ToolTipText = r.Item("NodeText2").ToString
Me.TreeView2.Nodes.Add(new_node)
Debug.Print(new_node.Name & " Created")
Else
'If Me.TreeView2.Nodes.ContainsKey(r.Item("NodeID").ToString) = False Then
'If Me.TreeView2.Nodes.ContainsKey(r.Item("NodeParent").ToString) = True Then
new_node = New TreeNode(r.Item("NodeID"))
new_node.Name = r.Item("NodeID")
new_node.Tag = r.Item("NodeID")
new_node.Text = r.Item("NodeText").ToString
new_node.ImageIndex = r.Item("NodeImageIndex").ToString
new_node.SelectedImageIndex = r.Item("NodeImageindexSelected").ToString
If Not r.Item("NodeText2") Is Nothing Then new_node.ToolTipText = r.Item("NodeText2").ToString


Dim no() As TreeNode = Me.TreeView2.Nodes.Find(r.Item("NodeParent"), True)
no(0).Nodes.Add(new_node)
Debug.Print(new_node.Name & " Created")
'Else
' MsgBox(Me.TreeView2.Nodes.ContainsKey(r.Item("NodeID").ToString).ToString())
' Debug.Print(r.Item("NodeID").ToString & " Cant be created parent " & r.Item("NodeParent").ToString & " does not exist")

'End If

'Else
' MsgBox("Node already exists")

'End If

End If
Next


End Sub

Continue reading...
 
Back
Top