Make one cell editable in datagridview c#

I've got a datagrid view with the property of readonly = true; But i want to set some cells editable, i try to do this with the next code:

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

But i can't modify the grid, someone had any idea?

Upvotes: 5

Views: 20054

Answers (4)

user4093832
user4093832

Reputation:

first remove dgv readonly true 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;
      }
  }

Upvotes: 5

Cartyui
Cartyui

Reputation: 1

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

Upvotes: 0

Yegor Korotetskiy
Yegor Korotetskiy

Reputation: 401

You could modify each cell within the column as read only where the cell value is not equal to 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's :-

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;
     }
}

Upvotes: 0

chouaib
chouaib

Reputation: 2817

try :

dgvNoCargadas[columns, index].ReadOnly = false;

Upvotes: 0

Related Questions