TreeNodeStates Enumeration

Note: This enumeration is new in the .NET Framework version 2.0.

Defines constants that represent the possible states of a TreeNode.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in

public enum class TreeNodeStates
/** @attribute FlagsAttribute() */ 
public enum TreeNodeStates
public enum TreeNodeStates

 Member nameDescription
CheckedThe node is checked. 
DefaultThe node is in its default state. 
FocusedThe node has focus. 
GrayedThe node is disabled. 
HotThe node is hot. This state occurs when the TreeView.HotTracking property is set to true and the mouse pointer is over the node. 
IndeterminateThe node in an indeterminate state. 
MarkedThe node is marked. 
SelectedThe node is selected. 
ShowKeyboardCuesThe node should indicate a keyboard shortcut. 

This enumeration is used by the State property of the DrawTreeNodeEventArgs class. For more information, see the TreeView.DrawNode event.

The following example demonstrates how to customize a TreeView control using owner drawing. The TreeView control in the example displays optional node tags alongside the normal node labels. Node tags are specified using the TreeNode.Tag property. The TreeView control also uses custom colors, including a custom highlight color.

You can customize most of the TreeView colors by setting color properties, but the selection highlight color is not available as a property. Additionally, the default selection highlight rectangle extends only around a node label. Owner drawing must be used to draw the node tags and to draw a customized highlight rectangle large enough to include a node tag.

In the example, a handler for the TreeView.DrawNode event draws unselected nodes by calling methods of the DrawTreeNodeEventArgs class. These methods provide the default appearance for TreeView elements that do not need customization. The handler draws the node tags and the custom selection highlight manually.

For the complete example, see the TreeView.DrawNode reference topic.

No code example is currently available or this language may not be supported.
// Draws a node.
private void myTreeView_DrawNode(Object sender, DrawTreeNodeEventArgs e)
    // Draw the background and node text for a selected node.
    if ((int)(e.get_State() & TreeNodeStates.Selected) != 0) {
        // Draw the background of the selected node. The NodeBounds
        // method makes the highlight rectangle large enough to
        // include the text of a node tag, if one is present.
        // Retrieve the node font. If the node font has not been set,
        // use the TreeView font.
        Font nodeFont = e.get_Node().get_NodeFont();
        if (nodeFont == null) {
            nodeFont = ((TreeView)sender).get_Font();
        // Draw the node text.
            nodeFont, Brushes.get_White(),
            RectangleF.op_Implicit(Rectangle.Inflate(e.get_Bounds(), 2, 0)));
    // Use the default background and node text.
    else {
    // If a node tag is present, draw its string representation 
    // to the right of the label text.
    if (e.get_Node().get_Tag() != null) {
            tagFont, Brushes.get_Yellow(), e.get_Bounds().get_Right() + 2,
    // If the node has focus, draw the focus rectangle large, making
    // it large enough to include the text of the node tag, if present.
    if ((int)(e.get_State() & TreeNodeStates.Focused) != 0) { 
        Pen focusPen = new Pen(Color.get_Black());
        try {
            Rectangle focusBounds = NodeBounds(e.get_Node());
            focusBounds.set_Size(new Size(focusBounds.get_Width() - 1,
                focusBounds.get_Height() - 1));
            e.get_Graphics().DrawRectangle(focusPen, focusBounds);
        finally {
} //myTreeView_DrawNode

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions