I am trying to enable and disable specific row in DataGridView by checking and unchecking of checkbox inside gridview. (C# Windows application)
I tried using the CellClick event which did not work as expected.
This is the code which i tried
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0 && dataGridView1.CurrentCell.Selected == true)
{
dataGridView1.Columns[3].ReadOnly = false;
}
}
please tell me how to do this.
Thanks in advance
I think you missed the CellContentClick event, try this:
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == dataGridView1.Columns["Your Column Name"].Index) //To check that we are in the right column
{
dataGridView1.EndEdit(); //Stop editing of cell.
if ((bool)dataGridView1.Rows[e.RowIndex].Cells["Your Column Name"].Value)
{
//dataGridView1.Columns[3].ReadOnly = true;// for entire column
int colIndex = e.ColumnIndex;
int rowIndex = e.RowIndex;
dataGridView1.Rows[colIndex].Cells[rowIndex].ReadOnly = 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