Make one cell editable in datagridview c #

I have a datagrid view with readonly = true; But I want some cells to be edited, I am trying to do it with the following code:

this.dgvNoCargadas.Rows[index].Cells[columns].ReadOnly = false;

      

But I can't change the grid, someone had an idea?

+4


source to share


4 answers


first remove the read-only dgv and then



  foreach (DataGridViewRow row in DataGridView1.Rows)
  {
      if (condition for true)
      {
          row.Cells[2].ReadOnly = true;
      }
      else (condition for false)
      {
          row.Cells[2].ReadOnly = false;
      }
  }

      

+4


source


try:



dgvNoCargadas[columns, index].ReadOnly = false;

      

0


source


You can change every cell in a read-only column if the cell value is not null or String.Empty. This will allow the user to edit those cells that are blank and protect your data.

Just loop through the DataGridViewRow: -

Foreach(DataGridViewRow row in DataGridView1.Rows)
{
   If(!row.Cells[2].Value.Equals(null) || !row.Cells[2].Value.Equals(String.Empty))
     {
        row.Cells[2].ReadOnly = true;
     }
}

      

0


source


    For Each row As DataGridViewRow In DataGridView1.Rows
        row.Cells('Cellnumber').ReadOnly = False
    Next

      

0


source







All Articles