把编辑器指派到个别单元格
有时,在同一列中的每个单元格并非都有相同的类型,并且在这些情况下可能需要把不同的编辑器指派到同一列中的不同单元格。 要把编辑器指派到个别单元格,则接管 TreeList.CustomNodeCellEdit 事件。 在接管此事件时,需要为每个个别单元格提供表示内置编辑器的特定的“repository 项”。 注意,所使用的“repository 项”必须被添加到 TreeList 的内部或外部存储库中。
下面的插图显示了编辑器被指派到个别单元格时的 XtraTreeList 控件。
在默认情况下,通过 TreeListColumn.ColumnEdit 属性或 TreeList.CustomNodeCellEdit 事件指派到单元格的编辑器也被用于编辑该单元格的内容。 如果需要把不同的编辑器用于内置编辑,则接管 TreeList.CustomNodeCellEditForEditing 事件。
示例
下面的示例代码接管了 TreeList.CustomNodeCellEdit 事件,进而指派了用于编辑两个节点的单元格取值的微调编辑器和复选编辑器。 假设这些编辑器已经被添加到了树状列表的存储库中。
下面的插图展示了运行结果。
C# | 复制代码 |
---|---|
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 Basic | 复制代码 |
---|---|
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 |