Skip to content

NodeComboBoxEnum

In contrast to the NodeComboBox node control, NodeComboBoxEnum allows displaying and editing bound data of an System.Enum type without additional code. The data to display can be either a bound object's property or node class's property.

To use NodeComboBoxEnum, add its instance to the NodeControls treeview property. It loads and manages the target enum type's items behind the scenes.

In the example below, the OrderSummaryNode custom node class has the OrderState enum field bound to the NodeComboBoxEnum node control. After running this example and clicking the node to edit it, a combo box dropdown will be shown with Created, InProcess, and Finished items.

Example

public enum OrderState
{
    Created,
    InProcess,
    Finished
}

class OrderSummaryNode : Node
{
    public string OrderName;
    public OrderState OrderState;
}

// create and bind node controls
NodeTextBox nameCtrl = new NodeTextBox();
nameCtrl.DataFieldName = "OrderName";
nameCtrl.AttachTo(tree);

NodeComboBoxEnum stateCtrl = new NodeComboBoxEnum(typeof(OrderState));
stateCtrl.DataFieldName = "OrderState";
stateCtrl.Editable = true;
stateCtrl.AttachTo(tree);

OrderSummaryNode orderNode = new OrderSummaryNode();
orderNode.OrderName = "Test order";
orderNode.OrderState = OrderState.InProcess;
orderNode.AttachTo(tree);
Public Enum OrderState
    Created
    InProcess
    Finished
End Enum

Class OrderSummaryNode
    Inherits Node
    Public OrderName As String
    Public OrderState As OrderState
End Class

' create and bind node controls
Dim nameCtrl As New NodeTextBox()
nameCtrl.DataFieldName = "OrderName"
nameCtrl.AttachTo(tree)

Dim stateCtrl As New NodeComboBoxEnum(GetType(OrderState))
stateCtrl.DataFieldName = "OrderState"
stateCtrl.Editable = True
stateCtrl.AttachTo(tree)

Dim orderNode As New OrderSummaryNode()
orderNode.OrderName = "Test order"
orderNode.OrderState = OrderState.InProcess
orderNode.AttachTo(tree)

Override item name#

By default, NodeComboBoxEnum fills the DropDownItems property with the specified enum item names when created. It provides the possibility to change the generated name of any item while keeping its original value. This is helpful when the enum item name is not descriptive to the user.

The example below shows how you can add more information for the user to every OrderState enum item name.

public enum OrderState
{
    Created,
    InProcess,
    Finished
}

// create and bind node controls
NodeTextBox nameCtrl = new NodeTextBox();
nameCtrl.DataFieldName = "OrderName";
nameCtrl.AttachTo(tree);

NodeComboBoxEnum stateCtrl = new NodeComboBoxEnum(typeof(OrderState));

// override dropdown item names.
stateCtrl.DropDownItems[0] = "Created (new order)";
stateCtrl.DropDownItems[1] = "In process";
stateCtrl.DropDownItems[2] = "Finished (order is closed)";

stateCtrl.DataFieldName = "OrderState";
stateCtrl.Editable = true;
stateCtrl.AttachTo(tree);

OrderSummaryNode orderNode = new OrderSummaryNode();
orderNode.OrderName = "Test order";
orderNode.OrderState = OrderState.InProcess;
orderNode.AttachTo(tree);
Public Enum OrderState
    Created
    InProcess
    Finished
End Enum

' create and bind node controls
Dim nameCtrl As New NodeTextBox()
nameCtrl.DataFieldName = "OrderName"
nameCtrl.AttachTo(tree)

Dim stateCtrl As New NodeComboBoxEnum(GetType(OrderState))

' at this time DropDownItems is already filled with enum item names
stateCtrl.DropDownItems(0) = "Created (new order)"
stateCtrl.DropDownItems(1) = "In process"
stateCtrl.DropDownItems(2) = "Finished (order is closed)"

stateCtrl.DataFieldName = "OrderState"
stateCtrl.Editable = True
stateCtrl.AttachTo(tree)

Dim orderNode As New OrderSummaryNode()
orderNode.OrderName = "Test order"
orderNode.OrderState = OrderState.InProcess
orderNode.AttachTo(tree)