Back to Devexpress

How to: Specify Different In-place Editors to Use in Display and Edit Modes

windowsforms-3084-controls-and-libraries-data-grid-examples-data-editing-how-to-specify-different-in-place-editors-to-use-in-display-and-edit-modes.md

latest2.9 KB
Original Source

How to: Specify Different In-place Editors to Use in Display and Edit Modes

  • Nov 13, 2018
  • 2 minutes to read

The following example demonstates how to assign different in-place editors to a column that will be used in display and edit modes respectively.

Assume that a grid column displays integer values that should be represented by a progress bar in display mode. In edit mode, a cell’s value must be edited by a spin editor.

To implement this task, a ProgressBar in-place editor must be assigned as the default editor to the column via the GridColumn.ColumnEdit property. This editor will be used to represent data in display mode. To provide a custom editor that will be used for in-place editing, the GridView.CustomRowCellEditForEditing event is handled.

The following image illustrates the result:

csharp
using DevExpress.XtraEditors.Repository;

// In-place editors used in display and edit modes respectively.
RepositoryItem editorForDisplay, editorForEditing;

private void Form1_Load(object sender, EventArgs e) {
    // Initialize the editors and assign the default editor to a column.
    editorForDisplay = new RepositoryItemProgressBar();
    editorForEditing = new RepositoryItemSpinEdit();
    gridView1.GridControl.RepositoryItems.AddRange( 
      new RepositoryItem[] { editorForDisplay, editorForEditing });
    gridView1.Columns["Quantity"].ColumnEdit = editorForDisplay;
}

// Provide the editor for in-place editing.
private void gridView1_CustomRowCellEditForEditing(object sender, 
  CustomRowCellEditEventArgs e) {
    if (e.Column.FieldName == "Quantity")
        e.RepositoryItem = editorForEditing;
}
vb
Imports DevExpress.XtraEditors.Repository

' In-place editors used in display and edit modes respectively.
Dim editorForDisplay, editorForEditing As RepositoryItem

Private Sub Form1_Load(ByVal sender As System.Object, _ 
  ByVal e As System.EventArgs) Handles MyBase.Load
    ' Initialize the editors and assign the default editor to a column.
    editorForDisplay = New RepositoryItemProgressBar()
    editorForEditing = New RepositoryItemSpinEdit()
    gridView1.GridControl.RepositoryItems.AddRange( _
      New RepositoryItem() {editorForDisplay, editorForEditing})
    gridView1.Columns("Quantity").ColumnEdit = editorForDisplay
End Sub

' Provide the editor for in-place editing.
Private Sub gridView1_CustomRowCellEditForEditing(ByVal sender As System.Object, _
  ByVal e As DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs) _
  Handles gridView1.CustomRowCellEditForEditing
    If e.Column.FieldName = "Quantity" Then
        e.RepositoryItem = editorForEditing
    End If
End Sub