title: How to allow editing of a datagridview programmatically?
body: <p>I have a datagridview connected to a database. I have a checkbox for enabling the data to be edited in datagridview. If the checkbox is checked then only 1 column of datagridview can be edited, and after editing click on save button to reflect it in database and when checkbox is unchecked editing is disabled.</p>
  
  <p>I've tried something like this:</p>
  
  <pre><code>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;
          }
      }
  </code></pre>
  
  <p>This code misses the concept of selecting the columns to be edited.</p>