I have a DataGridView
, where I want to disable some cells/rows with setting ReadOnly = true
.
What could be the reason that sometimes this has no effect and the cells/rows are still editable?
Are there other possibilities to prevent editing specific rows or cells? Is it possible to prevent clicking or entering a cell?
You could prevent editing with the CellBeginEdit event. If you dont want the cell to be edited, you can cancel the edit. For example, if you only want the first column to be editable, you can do this:
private void dataGridView1_CellBeginEdit(object sender,
DataGridViewCellCancelEventArgs e)
{
if (e.ColumnIndex != 0)
{
e.Cancel = true;
}
}
Try running a datagridview.Refresh()
after setting the readonly value to true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With