下面的示例展示了如何接管 GridView.CustomRowCellEdit 事件来把 ComboBoxEdit、SpinEdit 和 CheckEdit 编辑器指派到单元格,这依赖于 FieldName 列的值。 假设与这些编辑器对应的“repository 项”已经在一个 repository 中。
下面的屏幕截图展示了在代码执行前、后的网格控件的外观。 为达到演示目的,ColumnView.ShowButtonMode 属性值设置为 ShowButtonModeEnum.ShowAlways。
C# | 复制代码 |
---|---|
using DevExpress.XtraGrid.Views.Grid; private void gridView1_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e) { if (e.Column.FieldName == "FieldName") return; GridView gv = sender as GridView; string fieldName = gv.GetRowCellValue(e.RowHandle, gv.Columns["FieldName"]).ToString(); switch (fieldName) { case "Population": e.RepositoryItem = repositoryItemSpinEdit1; break; case "Country": e.RepositoryItem = repositoryItemComboBox1; break; case "Capital": e.RepositoryItem = repositoryItemCheckEdit1; break; } } |
Visual Basic | 复制代码 |
---|---|
Imports DevExpress.XtraGrid.Views.Grid Private Sub GridView1_CustomRowCellEdit(ByVal sender As Object, _ ByVal e As CustomRowCellEditEventArgs) _ Handles GridView1.CustomRowCellEdit If e.Column.FieldName = "FieldName" Then Return Dim Gv As GridView = sender Dim FieldName As String = Gv.GetRowCellValue(e.RowHandle, _ gv.Columns("FieldName")).ToString() Select Case (FieldName) Case "Population" e.RepositoryItem = repositoryItemSpinEdit1 Case "Country" e.RepositoryItem = repositoryItemComboBox1 Case "Capital" e.RepositoryItem = repositoryItemCheckEdit1 End Select End Sub |