I have a tree view over a Categories table which has parent ids which I am using to populate a treeview. I populate the root nodes and have code to populate child nodes as required.

However, I need to search on a category ID and expand the tree to show the tree structure for this category. In vb6 would populate a collection and use the treeview key property to populate the tree. As the key property does not exist, need some way to use the tag property in the same manner. I have created a collection as follows:

Private Function getCategoryChain(ByVal CategoryID As Integer) As Collection

Dim intParentID As Integer
Dim intCategoryID As Integer

intCategoryID = CategoryID
getCategoryChain = New Collection
getCategoryChain.Add(intCategoryID)

Do
intParentID = clsCategories.getParentCategory(intCategoryID)
If intParentID = -1 Then
MessageBox.Show(intCategoryID & " doesn't exist", "Category ID", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Function
End If
intCategoryID = intParentID
If intCategoryID <> 0 Then
getCategoryChain.Add(intCategoryID, , 1)
End If
Loop Until intParentID = 0


End Function

I am at a loss to know how I can create my tree structure from this collection.