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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

treeview explanation

Status
Not open for further replies.

clientuser

Programmer
Apr 18, 2001
296
US
Can anyone point me to some very beginner information on how to setup treeviews and use them properly? I have gotten some information about them, but its very difficult to understand..
 
Hi, a treeview can be tricky at first, it would be best if you found a book or documentation that explains it in detail, but here is a rundown. You can have root nodes which can have child nodes, which can have child nodes, etc, etc. You access the nodes through the nodes collection for the tree view. To add a root node:

Dim node as Node
Set node = tree.Nodes.Add relative, relationship, key, text, image, selected image

To add a child node to that node it is the same except that your relative is the one that you just created, and your relationship is as a child. The text propoerty is the text that will be shown for the node. The image & selected image properties are for displaying a icon with the text, one for regular node and one for selected node. You need to set up image controls for storing the different icons. The key is important. They keys need to be unique. What you need to do, especially if you are going to have a large tree going several levels inward is make sure that you set up the keys in a well structured manner, ie, before you code it think of how you are going to relate the nodes, and how you will set up a particular groups keys. For example if you had root nodes "A"-"Z", make the keys "A"-"Z", respectively. Now for A's child nodes make the keys "A_Something". Try to keep them in a pattern, it makes it easier.

Once you have it set up, you code event for a node click, etc. You will then probably have to reference a node's parents, children, text, and **keys**. At least for what I have used them for, the key for each node seems to be very important in having things run smoothly. There is a lot of little tricks to tree view, If I were you I would try to find a good solid example of a complex tree in a book or something. I could type pages on the tree view. Also, just take some time looking at all the different events and properties for the tree view, especially the nodes collection, that may give you a better understanding. Good Luck!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top