I am trying to populate a TreeView control with info from an array of information. The array contains phonebook entries and each entry has a category. What I want is to add the category to the TreeView if not already there, then populate descriptions as child nodes under that category. What is happening is the Nodes.Find method is not finding previously added category nodes so it is duplicating the categories in the list.
I must be missing something very basic here but I just can't seem to see it.Any insight would be most appreciated!
EDIT:
Ok, I figure out my issue was confusing the text property with the key/name property. For those interested, the Find method looks at a nodes Name, not it's Text. I added a line to add the text to the Name property and now Find works!
ie:
Public Sub RefreshList() tvSystemList.Nodes.Clear() Phonebook.Load() For Each item In Phonebook.catArray Dim srcnode() As TreeNode = tvSystemList.Nodes.Find(DirectCast(item, clsPhonebook._DVREntry).Category, False) If srcnode.Count > 0 Then srcnode(0).Nodes.Add(New TreeNode(DirectCast(item, clsPhonebook._DVREntry).Description)) Else Dim nodeidx As Integer = tvSystemList.Nodes.Add(New TreeNode(DirectCast(item, clsPhonebook._DVREntry).Category)) Dim newnode As TreeNode = tvSystemList.Nodes.Item(nodeidx) newnode.Nodes.Add(New TreeNode(DirectCast(item, clsPhonebook._DVREntry).Description)) End If Next End Sub
I must be missing something very basic here but I just can't seem to see it.Any insight would be most appreciated!
EDIT:
Ok, I figure out my issue was confusing the text property with the key/name property. For those interested, the Find method looks at a nodes Name, not it's Text. I added a line to add the text to the Name property and now Find works!
ie:
newnode.Name = newnode.Text
Last edited: