Winform Datagrid cell editing

When using manual row adding you can edit the grids cells by:

dataGrid.AutoGenerateColumns = false;
dataGrid.AllowUserToAddRows = false;

foreach (DataItem dataItem in allData)
int rowIndex = dataGrid.Rows.Add(new object[] {dataItem.Id, dataItem.Name});

if (dataItem.Enabled) continue;

//Here starts the row editing part
dataGrid[4, rowIndex].ReadOnly = true
dataGrid[4, rowIndex].Value = null;
dataGrid[4, rowIndex].Style.BackColor = Color.Red;

When using databinding this DOESN’t work!
You have to intercept events like CellBeginEdit and CellPainting
to change the behaviour.

Changing the data through a cell is not possible at all when databound.


%d bloggers like this: