O'Reilly logo

.NET Windows Forms in a Nutshell by Matthew Adams, Ian Griffiths

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

TreeView

Synopsis

This Control represents a hierarchical set of nodes in a tree view (similar to the Windows Explorer Folder View). You can add TreeNode objects to the Nodes collection. These are root nodes. To add further elements to the hierarchy you add additional TreeNode objects to the root TreeNode.Nodes collections. GetNodeCount() will return you the count of all nodes in the tree.

You can add CheckBoxes for each node, enable HotTracking (link-like) behavior, ShowLines and ShowRootLines (drawn from node to node), and ShowPlusMinus glyphs (little plus-shaped expansion boxes next to nodes with children). You can also set the distance by which to Indent each level of child nodes.

When you select an item, normally you are only permitted to click on imagery representing the label text. This can sometimes be awkward, so you can enable FullRowSelect to give users a larger target. HideSelection determines whether the selection highlight is displayed even when the control loses the focus. You can get or set the selected node with the SelectedNode property.

The nodes can be Sorted, and you can ExpandAll( ) and CollapseAll() nodes. To find the node under a particular point, you can use the GetNodeAt() method.

The tree raises events both Before and After select, check, collapse, and expand operations. If the control allows LabelEdit, you will also get BeforeLabelEdit and AfterLabelEdit events. The BeforeXXX events use the TreeViewCancelEventArgs class and can therefore be aborted.

 public ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required