HOME PAGE | DOWNLOAD | TUTORIALS | XtraReports
Devexpress

Sunday, July 22, 2012

How to: Assign Different Column Editors for Different Rows

The following example shows how to handle the GridView.CustomRowCellEdit event to assign ComboBoxEdit, SpinEdit and CheckEdit editors to cells, depending on the FieldName column value. It is assumed that the repository items corresponding to these editors are already in a repository.

The screenshots below show the grid's appearance before and after code execution. The ColumnView.ShowButtonMode property is set to ShowButtonModeEnum.ShowAlways for demonstration purposes.

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

 

No comments:

Post a Comment