8.17 Using the TreeNode Editor

 <  Day Day Up  >  

8.17 Using the TreeNode Editor

You want to use the TreeNode editor in the forms designer to add items to a TreeView control.


Technique

You display the TreeNode editor by selecting the Nodes property of a TreeView control in the property browser and clicking the edit button. Because a TreeView displays data hierarchically, you can choose to add a new root item or add a child to the currently selected node, as shown in Figure 8.7.

Figure 8.7. Use the TreeNode editor to populate your TreeView control with an initial set of TreeNode items.

graphics/08fig07.gif

Comments

The TreeView control displays data using a right-handed tree display scheme, which models hierarchical data through the notion of parent and child relationships. A good example of a tree control you've undoubtedly used is the folder tree within Windows Explorer. The roots of the tree contain the many different shell namespace objects such as "My Computer" or "My Documents." These root objects contain child items consisting of folders and files. Each folder is a child of one item and a parent of another, assuming , of course, the folder itself isn't empty.

When you launch the TreeNode editor from the Nodes property within the property browser, you see a dialog box like Figure 8.7. You use the editor to initially populate the tree control with static data items. As you add new root and child items, the forms designer modifies the InitializeComponent method within your form class by generating code that creates new TreeNode objects within the TreeView internal member object. To add new items using the TreeNode editor, you must first create a root item. As its name implies, the root item is the top-level item within the tree. However, the TreeView control is not singly rooted, which means you are free to create as many root items as necessary. A root item can be a parent or a sibling item but never a child, which means that any attempt to access a root item's Parent property results in a thrown exception. To add a child to an existing item, you must first select the parent item within the TreeNode editor and then click on the Add Child button.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net