Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Treeview Duplicates

Status
Not open for further replies.

patfree

MIS
Jun 27, 2005
5
US
I have successfully populated a treeview with user names and their applicable computer number as children. However, users that have multiple computer numbers assigned, have multiple listings in the tree. Is it possible to combine all duplicate user names into one and then add the computer numbers that were previously under the duplicate names after the tree is initially populated?

Thanks in advance for your help.
 
maybe you can sort the file you're reading by username. Then, when populating the tree, you could check if there's a change in username. If not, then do not add a node for the username but make a child node for the second computernumber.

 
I assume from your post that you are not assigning a key to the nodes as you add them.

I would advise doing so as it makes checking far easier.

For example
Code:
' To add a root level node (User)
If Not IsNode(UserName As String) Then
   Tree1.Nodes.Add , , UserName, UserName
End If

' To add a child node to a user (UserName)
If Not IsNode(ComputerId As String) Then
   Tree1.Nodes.Add UserName, tvwChild, ComputerId, ComputerId
End If

' Note that ComputerId must be non-numeric if used as a key
' If it is numeric, prefix it with a character
If Not IsNode("C" & ComputerId As String) Then
   Tree1.Nodes.Add UserName, tvwChild, "C" & ComputerId, ComputerId
End If

Private Function IsNode(ByVal Key As String) As Boolean

On Error Resume Next

' If Tree1.Nodes(Key) doesn't exist, error occurs and IsNode returns False
IsNode = (Tree1.Nodes(Key).Text <> "")

End Function

Hope this helps

Trevor
 
Thanks for the replies. TGandon, I've tried your code by I think I do not have the right ocx installed - the IsNode isn't recognized by my VB6. Suggestions?

Thanks again...
 
TGandon, I'm sorry for not paying attention. Now I see the Private Function IsNode(....
 
TGandon, I was able to tweak your code a little and it appears to work. Thank you so very much....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top