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 ...

Get .NET Windows Forms in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.