I have a datagridview related to a database. I have a checkbox allowing me to edit data in a datagridview. If the box is checked, then only 1 datagridview column can be edited, and after editing, click the "Save" button to reflect it in the database, and when the box is unchecked, editing is disabled.
I tried something like this:
private void checkBox1_CheckedChanged(object sender, EventArgs e) { if (checkBox1.CheckState == CheckState.Checked) { dataGridView1.CurrentRow.ReadOnly = false; dataGridView1.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2; } else if (checkBox1.CheckState == CheckState.Unchecked) { dataGridView1.ReadOnly = true; } }
This code lacks the concept of selecting columns for editing.
source share