下面的示例代码接管了 TreeList.CustomNodeCellEdit 事件,进而指派了用于编辑两个节点的单元格取值的微调编辑器和复选编辑器。 假设这些编辑器已经被添加到了树状列表的存储库中。

下面的插图展示了运行结果。

C#CopyCode image复制代码
using DevExpress.XtraTreeList;

private void treeList1_CustomNodeCellEdit(object sender, GetCustomNodeCellEditEventArgs e) {
   // Custom editors are assigned to all node cells except
   // for cells that reside within the "Category" column.
   if(e.Column.FieldName != "Category") {
      // Obtain the record's first field value.
      switch(e.Node.GetValue(0).ToString()) {
            // A spin editor is assigned to the cells of the "Units in Stock" row.
         case "Units in Stock": 
            e.RepositoryItem = repositoryItemSpinEdit1;
            break;
            // A check editor is assigned to the cells of the "Discontinued" row.
         case "Discontinued": 
            e.RepositoryItem = repositoryItemCheckEdit1;
            break;
      }
   }
}

Visual BasicCopyCode image复制代码
Imports DevExpress.XtraTreeList

Private Sub TreeList1_CustomNodeCellEdit(ByVal sender As Object, _
ByVal e As GetCustomNodeCellEditEventArgs) Handles TreeList1.CustomNodeCellEdit
   ' Custom editors are assigned to all node cells except
   ' for cells that reside within the "Category" column.
   If e.Column.FieldName <> "Category" Then
      ' Obtain the record's first field value.
      Select Case e.Node.GetValue(0).ToString()
         ' A spin editor is assigned to the cells of the "Units in Stock" row.
         Case "Units in Stock"
            e.RepositoryItem = RepositoryItemSpinEdit1
         ' A check editor is assigned to the cells of the "Discontinued" row.
         Case "Discontinued"
            e.RepositoryItem = RepositoryItemCheckEdit1
      End Select
   End If
End Sub