private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[0].Value != null && row.Cells[0].Value.Equals(true)) //0 is the column number of checkbox { row.Selected = true; BtnCancel.Enabled = false; row.DefaultCellStyle.SelectionBackColor = Color.LightSlateGray; } else row.Selected = false; BtnCancel.Enabled = true; btnUpdate.Enabled = true; btnDelete.Enabled = true; } private void dataGridView1_SelectionChanged(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count == 0) return; dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.SelectedRows[0].Index; } private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { if (e.ColumnIndex == 0) { return; } else { cellValue = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; } // For this demo we will make exception for checkBoxColumn itself. // So it is always editable. if (e.ColumnIndex != chkbox.Index) { object rawValue = dataGridView1[chkbox.Index, e.RowIndex].Value; bool value = rawValue is bool ? (bool)rawValue : false; // But if checkBoxColumn is checked then editing not allowed if (!value) { e.Cancel = true; } } }
else row.Selected = false; BtnCancel.Enabled = true; btnUpdate.Enabled = true; btnDelete.Enabled = true;
else { row.Selected = false; BtnCancel.Enabled = true; btnUpdate.Enabled = true; btnDelete.Enabled = true; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)