Assigning Editors to Individual Cells

  • 2 minutes to read

Assigning Editors to Individual Cells

Sometimes not every cell in a column is the same type, and in these cases you may want to assign different editors to different cells in the same column. To assign editors to individual cells, handle the TreeList.CustomNodeCellEdit event. While handling this event, you need to provide specific repository items, representing in-place editors, for each individual cell. Note that repository items being used must be added to the TreeList's internal repository (the EditorContainer.RepositoryItems inherited property) or external repository (the EditorContainer.ExternalRepository inherited property).

The image below displays the Tree List control when editors are assigned to individual cells.

cdInplaceEditors

By default, the editor assigned to a cell via the TreeListColumn.ColumnEdit property or TreeList.CustomNodeCellEdit event will be also 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 sample code handles the TreeList.CustomNodeCellEdit event to assign different in-place editors (repository items) to cells. It's assumed that these editors have already been added to the Tree List's repository.

The image below shows the result.

cdInplaceEditors

using DevExpress.XtraTreeList;

private void treeList1_GetCustomNodeCellEdit(object sender, DevExpress.XtraTreeList.GetCustomNodeCellEditEventArgs e) {
    if(e.Column.FieldName != "Category") {
        object obj = e.Node.GetValue(0);
        if(obj != null) {
            switch(obj.ToString()) {
                case "Category":
                    e.RepositoryItem = repositoryImageComboBox1;
                    break;
                case "Supplier":
                    e.RepositoryItem = repositoryItemComboBox1;
                    break;
                case "Unit Price":
                    e.RepositoryItem = repositoryItemCalcEdit1;
                    break;
                case "Units in Stock":
                    e.RepositoryItem = repositoryItemSpinEdit1;
                    break;
                case "Discontinued":
                    e.RepositoryItem = repositoryItemCheckEdit1;
                    break;
                case "Last Order":
                    e.RepositoryItem = repositoryItemDateEdit1;
                    break;
                case "Relevance":
                    e.RepositoryItem = repositoryItemProgressBar1;
                    break;
                case "Phone":
                    e.RepositoryItem = repositoryItemTextEdit1;
                    break;
            }
        }
    }
}
See Also