Get started
Column controls are a type of node control but displayed in the treeview column headers. Below is an example of the DropDownColumnControl, which shows a dropdown menu when clicked.
The column controls can be added to the treeview in two different ways described below.
Add column controls in designer#
You can use Visual Studio's Windows Forms designer to add column controls to the treeview. To do that, open the Flexible TreeView Columns treeview property designer, click the specific column where you want to add the column control, and open its Controls property designer as shown in the screenshot below.
Now, by clicking the Add button, different types of column controls can be added to the selected column.
Add column controls in code#
The other way to add column controls is manually in code. All column controls are linked to the specific column where they should be displayed. To add or remove the column control, use the TreeColumn.Controls property.
For example, below we will add an instance of the DropDownColumnControl to the column.
// Create a new DropDownColumnControl instance.
DropDownColumnControl dropDownControl = new DropDownColumnControl();
ContextMenuStrip columnMenu = new ContextMenuStrip();
ToolStripButton optionsMenuItem = new ToolStripButton("Options", null, OnColumnOptionsClick);
columnMenu.Items.Add(optionsMenuItem);
columnMenu.AutoSize = false;
dropDownControl.DropDownContent = columnMenu;
// Create a new TreeColumn and add the DropDownColumnControl.
TreeColumn column = new TreeColumn("Order details");
tree.Columns.Add(column);
column.Controls.Add(dropDownControl);
void OnColumnOptionsClick(object sender, EventArgs eventArgs)
{
MessageBox.Show("Show column options");
}
' Create a new DropDownColumnControl instance.
Dim dropDownControl As New DropDownColumnControl()
Dim columnMenu As New ContextMenuStrip()
Dim optionsMenuItem As New ToolStripButton("Options", Nothing, AddressOf OnColumnOptionsClick)
columnMenu.Items.Add(optionsMenuItem)
columnMenu.AutoSize = False
dropDownControl.DropDownContent = columnMenu
' Create a new TreeColumn and add the DropDownColumnControl.
Dim column As New TreeColumn("Order details")
tree.Columns.Add(column)
column.Controls.Add(dropDownControl)
Private Sub OnColumnOptionsClick(sender As Object, eventArgs As EventArgs)
MessageBox.Show("Show column options")
End Sub