Skip to content

DevExpress-Examples/winforms-grid-multi-cell-editing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WinForms Data Grid - Simultaneous editing of several cell values

This example shows how to edit the values ​​in selected cells at the same time.

Edit Values in Selected Cells - WinForms Data Grid

bool lockEvents;
private void OnCellValueChanged(CellValueChangedEventArgs e)
{
    if (lockEvents)
        return;
    lockEvents = true;
    SetSelectedCellsValues(e.Value);
    lockEvents = false;
}
private void SetSelectedCellsValues(object value)
{
    try {
        view.BeginUpdate();
        GridCell[] cells = view.GetSelectedCells();
        ChangeMode mode = (ChangeMode)radioGroup.EditValue;
        foreach(GridCell cell in cells) {
            int rowHandle = cell.RowHandle;
            GridColumn column = cell.Column;
            switch(mode) {
                case ChangeMode.All:
                    break;
                case ChangeMode.Column:
                    column = view.FocusedColumn;
                    break;
                case ChangeMode.Row:
                    rowHandle = view.FocusedRowHandle;
                    break;
            }
            view.SetRowCellValue(rowHandle, column, value);
        }
    }
    catch(Exception ex) { }
    finally { view.EndUpdate(); }
}

Files to Review