Skip to Content
.NET Windows Forms in a Nutshell
book

.NET Windows Forms in a Nutshell

by Ian Griffiths, Matthew Adams
March 2003
Intermediate to advanced
896 pages
32h 35m
English
O'Reilly Media, Inc.
Content preview from .NET Windows Forms in a Nutshell

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Windows Forms 2.0 Programming

Windows Forms 2.0 Programming

Chris Sells, Michael Weinhardt
Pro C# 7: With .NET and .NET Core

Pro C# 7: With .NET and .NET Core

Andrew Troelsen, Philip Japikse

Publisher Resources

ISBN: 0596003382Supplemental ContentCatalog PageErrata