NodeComboBox

NodeComboBox displays a single item from a list and allows users to change the selection using a combo box control. To specify the available items, populate the DropDownItems node control property as shown in the example below.

This node control tracks the index of the selected item, so it must be bound to a numeric type convertible to System.Int. The Nullable<System.Int> type is also supported; in this case, when the bound value is NULL, NodeComboBox displays no data.

The below example outlines how to bind the NodeComboBox to a node member that holds the selected item index.

// Custom node class to hold the selected item index.
class NodeEx : Node
{
    public int Position { get; set; }
}

NodeComboBox cb = new NodeComboBox();
cb.AttachTo(tree);
// define the combo box items list.
string[] objects = new[] { "First", "Second", "Third" };
cb.DropDownItems = new List<object>(objects);

// binds NodeComboBox to the node member with the selected index.
cb.DataFieldName = "Position";

NodeEx node = new NodeEx();
// second position (zero based) by default is selected.
node.Position = 1;
node.AttachTo(tree);
' Custom node class to hold the selected item index.
Class NodeEx
    Inherits Node
    Public Position As Integer
End Class

Dim cb As New NodeComboBox()
cb.AttachTo(tree)
' define the combo box items list.
Dim objects As String() = New String() {"First", "Second", "Third"}
cb.DropDownItems = New List(Of Object)(objects)

' binds NodeComboBox to the node member with the selected index.
cb.DataFieldName = "Position"

Dim node As New NodeEx()
' second position (zero based) by default is selected.
node.Position = 1
node.AttachTo(tree)

Additionally, the combo box item list can be defined dynamically by enabling the InteractiveDropDownItems node control property and subscribing to the NodeComboBoxGetItems TreeView event, as demonstrated below.

// Custom node class to hold the selected item index.
class NodeEx : Node
{
    public int Position { get; set; }
}

NodeComboBox cb = new NodeComboBox();
// enable the dynamic combo box items mode.
cb.InteractiveDropDownItems = true;
cb.DataFieldName = "Position";
// Optional. Apply when you need to edit data in the combo box.
cb.Editable = true;
cb.AttachTo(tree);

// handle the event to supply the combo box items list.
tree.NodeComboBoxGetItems += tree_NodeComboBoxGetItems;

// add node.
NodeEx node = new NodeEx();
// default selected item's index.
node.Position = 1;
node.AttachTo(tree);

private void tree_NodeComboBoxGetItems(FlexibleTreeView treeview, NodeComboBoxGetItemsEventArgs args)
{
    // supply the combo box's dropdown items list.
    args.Items = new string[] { "First", "Second", "Third" };
}
' Custom node class to hold the selected item index.
Class NodeEx
    Inherits Node
    Public Position As Integer
End Class

Dim cb As New NodeComboBox()
' enable the dynamic combo box items mode.
cb.InteractiveDropDownItems = True
cb.DataFieldName = "Position"
' Optional. Apply when you need to edit data in the combo box.
cb.Editable = True
cb.AttachTo(tree)

' handle the event to supply the combo box items list.
AddHandler tree.NodeComboBoxGetItems, AddressOf tree_NodeComboBoxGetItems

' add node.
Dim node As New NodeEx()
' default selected item's index.
node.Position = 1
node.AttachTo(tree)

Private Sub tree_NodeComboBoxGetItems(treeview As FlexibleTreeView, args As NodeComboBoxGetItemsEventArgs)
    ' supply the combo box's dropdown items list.
    args.Items = New String() {"First", "Second", "Third"}
End Sub

Tip

To limit the number of items displayed in the combo box drop-down, use the MaxDropDownItems property of the control.