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?
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;
}
}
尝试:
dgvNoCargadas[columns, index].ReadOnly = false;
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;
}
}
For Each row As DataGridViewRow In DataGridView1.Rows
row.Cells('Cellnumber').ReadOnly = False
Next
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.