Setting Up the Tree View

To set up a TreeView, start by dragging a TreeView control from the Toolbox onto a form and positioning and sizing it accordingly. Then define the items to be displayed in the tree, which are called nodes and are represented by TreeNode objects. If you have used Windows Explorer, you'll be familiar with the fact that nodes in a TreeView usually have a small graphic associated with them, and that the graphic changes to show whether a node is selected or not.

The images used for selected and unselected nodes are held in an ImageList, so the next task is to add an ImageList object to the form and fill it with images. You can do this by clicking on the button to the right of the Images property of the ImageList and choosing graphics files in the Image Collection Editor, as shown in Figure 10.35. Once you've done this, set the ImageList property of the TreeView to point to the ImageList you've just created, so that the TreeView knows what images it has to use.

0 0

Post a comment