Tag Archives: TreeNode

Check a TreeView subtree in C#

Sometimes it’s useful to let the user select a TreeView subtree by clicking on a higher-level node. Then the user can deselect individual nodes within the subtree if desired. For example, in the picture shown here I checked the Dinner … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , , , | 4 Comments

Display context menus for TreeView items in C#

This example displays different context menus when you right-click on different kinds of nodes in a TreeView control. In this example, different nodes represent factories, groups, or individuals. Different node types display different context menus. When it starts, the program … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , | Leave a comment

Enumerate TreeView nodes in C#

The previous two posts show two ways you can enumerate TreeView nodes that are checked. The idea is to recursively crawl over the tree’s nodes and pick out the checked ones. Unfortunately that method isn’t easily extendable. For example, if … Continue reading

Posted in algorithms, controls, recursion, user interface | Tagged , , , , , , , , , , , , , , , , | Leave a comment

Yield checked TreeView nodes in C#

The previous example used recursion to traverse the nodes in a TreeView control and fill a list with the nodes that are checked. This example uses a slightly different approach. It traverses the TreeView control’s nodes and uses the yield … Continue reading

Posted in algorithms, controls, recursion, user interface | Tagged , , , , , , , , , , , , , , | Leave a comment

Make a list of checked TreeView nodes in C#

If you set a TreeView control’s CheckBoxes property to true, then the control displays boxes that the user can check to select nodes. In that case you will probably need to find the checked TreeView nodes at some point. Strangely … Continue reading

Posted in algorithms, controls, recursion, user interface | Tagged , , , , , , , , , , , , , | Leave a comment

Display a form’s control hierarchy in C#

This example displays the control hierarchy for a form. It’s actually relatively simple. Some controls can contain other controls. For example, a form is a control and it contains all of a Windows Forms application’s controls. Similarly Panel, TableLayoutPanel, SplitContainer, … Continue reading

Posted in controls, forms | Tagged , , , , , , , , , , , , | Leave a comment

Draw a scrolling family tree in C#

The example Draw a family tree in C# shows how to draw a family tree. Unfortunately if the tree is too big, you can’t make the form big enough to display it all. One solution would be to use smaller … Continue reading

Posted in algorithms, classes, generic, graphics, OOP | Tagged , , , , , , , , , , , , , , , , , , , , , | 1 Comment

Draw trees vertically or horizontally in C#

The example Handle generic TreeNode mouse events in C# shows how to build a generic node class that can draw trees with nodes that contain just about anything. In that example, each each node is centered over its subtree. This … Continue reading

Posted in algorithms, classes, drawing, graphics | Tagged , , , , , , , , , , , , , , , , , , | 3 Comments

Make a generic TreeNode class with link weights in C#

The post Handle generic TreeNode mouse events in C# explains how you can build and draw a tree where the nodes contain generic items. This example adds the ability to display link weights. The generic TreeNode class now has a … Continue reading

Posted in algorithms, classes, generic, OOP | Tagged , , , , , , , , , , , , , | 6 Comments

Draw a family tree in C#

This example shows how to use the generic TreeNode class to draw a family tree. The example Draw a tree with nodes containing pictures in C# draws a picture showing part of the British royal family tree. It works, but … Continue reading

Posted in classes, generic, OOP | Tagged , , , , , , , , , , , , , , , , | 12 Comments