How does treeview.contains identifer the node ?

  • Thread starter Thread starter Milosz - [playseven.com]
  • Start date Start date
M

Milosz - [playseven.com]

Dim hIP As TreeNode

hIP = New TreeNode("Peter")

Dim myNodeCollection As TreeNodeCollection = Me.treeResults.Nodes
If Not myNodeCollection.Contains(hIP) Then

Me.treeResults.Nodes.Add(hIP)

Else

hIP = treeResults.Nodes(Me.treeResults.Nodes.IndexOf(hIP))

End If

calling this code twice, it is not recognized that Peter is already added
so how determine that peter is already added ?






--
-> Milosz Weckowski
www.playseven.com

mailto:[email protected]
ICQ Number: 84867613

Get the enhanced Progressbar and a fine Colorpicker for the Compact Framwork for free:
http://www.playseven.com/11620/p7_Controls.html
 
If this is your exact code, then calling it for the 2nd time will create another copy of "Peter" and If Not myNodeCollection.Contains(hIP) will be true again (new node).
Dim hIP As TreeNode

hIP = New TreeNode("Peter")

Dim myNodeCollection As TreeNodeCollection = Me.treeResults.Nodes
If Not myNodeCollection.Contains(hIP) Then

Me.treeResults.Nodes.Add(hIP)

Else

hIP = treeResults.Nodes(Me.treeResults.Nodes.IndexOf(hIP))

End If

calling this code twice, it is not recognized that Peter is already added
so how determine that peter is already added ?






--
-> Milosz Weckowski
www.playseven.com

mailto:[email protected]
ICQ Number: 84867613

Get the enhanced Progressbar and a fine Colorpicker for the Compact Framwork for free:
http://www.playseven.com/11620/p7_Controls.html
 
yes, I know Alex
and that's my problem ...
so how to recognize that a node with "Peter" is already added ?
step through the collection manually and compare strings ?
so the function contains() would be nearly useless, and i can't believe it.
how to do it ?


regards

Milosz


If this is your exact code, then calling it for the 2nd time will create another copy of "Peter" and If Not myNodeCollection.Contains(hIP) will be true again (new node).
Dim hIP As TreeNode

hIP = New TreeNode("Peter")

Dim myNodeCollection As TreeNodeCollection = Me.treeResults.Nodes
If Not myNodeCollection.Contains(hIP) Then

Me.treeResults.Nodes.Add(hIP)

Else

hIP = treeResults.Nodes(Me.treeResults.Nodes.IndexOf(hIP))

End If

calling this code twice, it is not recognized that Peter is already added
so how determine that peter is already added ?






--
-> Milosz Weckowski
www.playseven.com

mailto:[email protected]
ICQ Number: 84867613

Get the enhanced Progressbar and a fine Colorpicker for the Compact Framwork for free:
http://www.playseven.com/11620/p7_Controls.html
 
Contains cannot operate the way you want it to for a simple reason that you are allowed to have more than one node with the same text in the treeview. In your case you might want to add every node you create to a Hashtable using the text as a key. If you do this, Hastable.Contains can be used to identify existing nodes by their text quickly. Memory overhead is small as we are dealing with reference types here.
yes, I know Alex
and that's my problem ...
so how to recognize that a node with "Peter" is already added ?
step through the collection manually and compare strings ?
so the function contains() would be nearly useless, and i can't believe it.
how to do it ?


regards

Milosz


If this is your exact code, then calling it for the 2nd time will create another copy of "Peter" and If Not myNodeCollection.Contains(hIP) will be true again (new node).
Dim hIP As TreeNode

hIP = New TreeNode("Peter")

Dim myNodeCollection As TreeNodeCollection = Me.treeResults.Nodes
If Not myNodeCollection.Contains(hIP) Then

Me.treeResults.Nodes.Add(hIP)

Else

hIP = treeResults.Nodes(Me.treeResults.Nodes.IndexOf(hIP))

End If

calling this code twice, it is not recognized that Peter is already added
so how determine that peter is already added ?






--
-> Milosz Weckowski
www.playseven.com

mailto:[email protected]
ICQ Number: 84867613

Get the enhanced Progressbar and a fine Colorpicker for the Compact Framwork for free:
http://www.playseven.com/11620/p7_Controls.html
 
Back
Top