更新时间:2022-06-12 06:52:59
我认为您错过了 CellContentClick 事件,请尝试以下操作:
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;
}
}
}