Assigning Editors to Columns
- 2 minutes to read
Online Video
WinFormsTree List - How To Assign Editors To Columns Using Code.
Assigning Editors to Columns
The most common way of using in-place editors is by assigning them to columns. This is a typical scenario, since columns are usually presented as a number of fields that contain values of the same type. You can assign different editors to columns with respect to their type. An in-place editor can be assigned to a column as follows:
- Create a corresponding repository item object, representing the required in-place editor.
- Add the repository item to the internal or external repository.
- Assign it to the TreeListColumn.ColumnEdit property.
The image below shows an example of assigning various editors to Tree List columns.
At design time, the TreeListColumn.ColumnEdit property provides a dropdown window that enables quick in-place editor assignment. The dropdown allows you to create a new in-place editor (repository item), or choose from among existing in-place editors. If you create a new in-place editor at design time, it’s automatically added to the Tree List’s internal repository.
For more information about repositories, see the Inplace Editors document.
By default, the editor assigned to a cell via the TreeListColumn.ColumnEdit property or TreeList.CustomNodeCellEdit event will also be used for editing the cell’s contents. If you want to use a different editor for in-place editing, handle the TreeList.CustomNodeCellEditForEditing event.
Example
The following example demonstrates how to create and adjust a new in-place editor (ComboBoxEdit). The editor is bound to the “Location” column using the TreeListColumn.ColumnEdit property.
The screenshot below demonstrates the result of the code’s execution
using DevExpress.XtraEditors.Repository;
//Create a repository item corresponding to a combo box editor.
RepositoryItemComboBox riCombo = new RepositoryItemComboBox();
riCombo.Items.AddRange(new string[] {"San Francisco", "Monterey", "Toronto", "Boston", "Kuaui", "Singapore", "Tokyo"});
//Add the item to the internal repository
treeList1.RepositoryItems.Add(riCombo);
//Now you can define the repository item as an in-place column editor
columnLocation.ColumnEdit = riCombo;