How to: Assign editors to individual cells

  • 2 minutes to read

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;
            }
        }
    }
}