ComboTree control is a control that combines the selection control with drop-down tree control. It is similar to ComboBox control but it does not have editing capabilities but it does have multiple column binding and auto grouping functionality built-in. Here is how ComboTree control looks like:
Clicking the drop-down button will show the tree control:
ComboTree can bind to any data source that supports IList or IListSource interfaces such as DataSet or an array. Here are steps to bind ComboTree to a data source:
- Set DataSource property to your data source
- Set DisplayMembers property to comma separated list of field names that you want to display on popup tree control. For example setting this property to ContactName,Phone will display these two fields on popup.
- Optionally set SelectedDisplayMemeber property to a field name that holds the selected value that you want displayed in control while popup is not visible.
- Optionally set ValueMember property to the field name that is used as actual value of the control. The ComboTree.SelectedValue property will return value of this field when selection changes.
- Optionally set GroupingMembers property to comma separated list of fields you want control to group data by. For example setting this property to Country will group the data on popup by country name. For alternative grouping option see next step.
- Optionally set ParentFieldNames property to comma separated field names that are used as identifiers for node and parent node. Format expected is: FieldNodeId,ParentNodeFieldId. For example if your table represents departments, you have DepartmentId field which uniquely identifies a department and ParentDepartmentId field which identifies parent of the department if any you would set this property to DepartmentId,ParentDepartmentId.
- If needed, handle SelectedIndexChanged event which occurs when selection in ComboTree changes.
When you set DisplayMembers property the control automatically generates the column and sets default size for them. In case that you want to set custom size for the columns or create them using code you must leave this property empty and manually create columns by using Edit Columns… command that is accessible if you right-click ComboTree in VS.NET designer or creating them using code.
For each new column header you create simply set Text property to the column header and DataFieldName property to the name of the field in your data source that holds the column value. You can change width of column by changing values on Width object.
You can control the drop down width and height by using DropDownWidth and DropDownHeight properties on ComboTree.
To control whether keyboard search is enabled use KeyboardSearchEnabled property. Keyboard search allows you to start typing while controls has focus and search the content of the control and select it based on the text you type.
You can display additional buttons or even hide default drop-down button by using ButtonClear, ButtonDropDown, ButtonCustom and ButtonCustom2 properties.