Skip to main content
A newer version of this page is available. .

GridView.CustomRowCellEdit Event

Enables you to assign editors to individual cells.

Namespace: DevExpress.XtraGrid.Views.Grid

Assembly: DevExpress.XtraGrid.v17.2.dll

Declaration

[DXCategory("Editor")]
public event CustomRowCellEditEventHandler CustomRowCellEdit

Event Data

The CustomRowCellEdit event's data class is CustomRowCellEditEventArgs. The following properties provide information specific to this event:

Property Description
CellValue Returns the currently processed cell value. Inherited from CustomRowCellEventArgs.
Column Gets the column to which the currently processed cell corresponds. Inherited from CustomRowCellEventArgs.
RepositoryItem Gets or sets the editor used to edit the currently processed cell.
RowHandle Gets the handle of the row that contains the processed cell. Inherited from CustomRowCellEventArgs.

Remarks

The CustomRowCellEdit event fires for each cell within the View. The referenced cell is identified by the event’s CustomRowCellEventArgs.Column and CustomRowCellEventArgs.RowHandle parameters. If you need to change the cell’s editor, assign a specific RepositoryItem descendant to the CustomRowCellEditEventArgs.RepositoryItem property.

The image below shows a View where editors are assigned to cells via the CustomRowCellEdit event, depending on the rows where the cells reside. This makes the View appear rotated 90 degrees (rows serve as columns).

CustomRowCellEditor

By default, the editor assigned to a cell via the GridColumn.ColumnEdit property or the GridView.CustomRowCellEdit event will also be used for editing the cell’s contents. If you want to use a different editor for in-place editing, handle the GridView.CustomRowCellEditForEditing event.

To replace default editors within the Edit Form. with custom ones, handle the GridView.CustomRowCellEditForEditing event. The CustomRowCellEdit event cannot be used for this purpose.

Note

If you handle the CustomRowCellEdit event to supply an editor for a specific row depending on it’s focused state, this editor will not be used for editing. In this instance, to use a specific editor for editing, you should handle the GridView.CustomRowCellEditForEditing event.

Note

Due to the Grid Control’s infrastructure, the CustomRowCellEdit event fires frequently - each time a cell is refreshed. Therefore, do not update the grid’s visual elements (cell values, layout, etc.) or implement complex logic for your CustomRowCellEdit event handler. Otherwise, your application performance might be severely affected.

Note

Do not change properties of existing RepositoryItems (including the e.RepositoryItem object) in your CustomRowCellEdit event handler. The CustomRowCellEdit event must be used only for providing a specific RepositoryItem based on the processed row and column, but not for changing properties of existing items. The correct approach is to create RepositoryItem objects and customize them beforehand, and then handle the CustomRowCellEdit event to assign these RepositoryItem objects to the event’s e.RepositoryItem parameter, based on your logic.

For more information about assigning editors to individual cells, see the Modify and Validate Cell Values topic.

Example

This example shows how to assign different in-place editors (CalcEdit, SpinEdit and TextEdit) to different grid cells by handling the GridView.CustomRowCellEdit event.

CustomRowCellEdit-example

public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        List<MyRecord> dataSource = new List<MyRecord>();
        RepositoryItemSpinEdit riSpinEdit = new RepositoryItemSpinEdit();
        RepositoryItemCalcEdit riCalcEdit = new RepositoryItemCalcEdit();
        RepositoryItemTextEdit riTextEdit = new RepositoryItemTextEdit();
        RepositoryItem[] inplaceEditors;


        private void Form1_Load(object sender, EventArgs e) {
            inplaceEditors = new RepositoryItem[] { riSpinEdit, riTextEdit, riCalcEdit };

            GridControl gridControl1 = new GridControl();
            this.Controls.Add(gridControl1);
            gridControl1.Dock = DockStyle.Fill;

            for (int i = 0; i < 3; i++)
                dataSource.Add(new MyRecord((i+1) * i, (i+1) * i + 10, (i+1) * i + 20));
            gridControl1.DataSource = dataSource;

            gridControl1.RepositoryItems.Add(riSpinEdit);
            gridControl1.RepositoryItems.Add(riCalcEdit);
            gridControl1.RepositoryItems.Add(riTextEdit);

            GridView gridView1 = gridControl1.MainView as GridView;
            gridView1.CustomRowCellEdit += GridView1_CustomRowCellEdit;
            gridView1.OptionsView.ShowButtonMode = DevExpress.XtraGrid.Views.Base.ShowButtonModeEnum.ShowAlways;

            riTextEdit.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
            riTextEdit.DisplayFormat.FormatString = "c2";


        }

        private void GridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e) {
            GridView view = sender as GridView;
            int editorIndex = (view.GetDataSourceRowIndex(e.RowHandle) + e.Column.VisibleIndex) % 3;
            e.RepositoryItem = inplaceEditors[editorIndex];
        }
    }

    public class MyRecord {
        public MyRecord(int val1, int val2, int val3) {
            Column1 = val1;
            Column2 = val2;
            Column3 = val3;
        }
        public int Column1 { get; set; }
        public int Column2 { get; set; }
        public int Column3 { get; set; }
    }

The following code snippets (auto-collected from DevExpress Examples) contain references to the CustomRowCellEdit event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also