Updating Treeview

curlydog

Well-known member
Joined
Jul 5, 2010
Messages
50
Programming Experience
Beginner
I have a treeview control in a vb form which displays the results of a user's search. I'm using several backgroundworkers that conduct the search before displaying their results in the treeview.

The search results are returned in the form of an arraylist of "searchHit" objects. My issue relates to updating the treeview when the results are returned. When the first arraylist is returned, the treeview will be empty. When subsequent arraylists are returned, the treeview may already have some nodes. I need to update the treeview, dependant of what is already displayed.

By way of an example. If I have a search that retrieves books with a certain word in the title, there may be numerous books returned, by numerous authors. When my results are returned, I need to check if there is already a node for the author. If the node exists I need to add a book as a child node. If the author doesn't exist, I need to add the author and then add the book as a child node. In this example, my "searchHit" object contains the name and ID of the book as well as the name and the ID of the author. There is one "searchHit" object per book.

I need to know how to iterate through the existing (if any) authors and either add a book to an existing author, or add a new author and the book.

Any help would be appreciated, particularly any sample code.

Many thanks
Jason
 
Set the Name property of the TreeNode, this works as lookup 'id' for the Treeview.Nodes.Find method.
 
Back
Top