【发布时间】:2015-01-11 14:35:21
【问题描述】:
我有一个具有 readonly = true 属性的数据网格视图;但我想设置一些可编辑的单元格,我尝试使用下一个代码来做到这一点:
this.dgvNoCargadas.Rows[index].Cells[columns].ReadOnly = false;
但是我不能修改网格,有人知道吗?
【问题讨论】:
标签: c# winforms gridview datagridview
我有一个具有 readonly = true 属性的数据网格视图;但我想设置一些可编辑的单元格,我尝试使用下一个代码来做到这一点:
this.dgvNoCargadas.Rows[index].Cells[columns].ReadOnly = false;
但是我不能修改网格,有人知道吗?
【问题讨论】:
标签: c# winforms gridview datagridview
首先删除dgv readonly true 然后
foreach (DataGridViewRow row in DataGridView1.Rows)
{
if (condition for true)
{
row.Cells[2].ReadOnly = true;
}
else (condition for false)
{
row.Cells[2].ReadOnly = false;
}
}
【讨论】:
For Each row As DataGridViewRow In DataGridView1.Rows
row.Cells('Cellnumber').ReadOnly = False
Next
【讨论】:
您可以将列中的每个单元格修改为只读,其中单元格值不等于 null 或 String.Empty。这将允许用户编辑那些空白的单元格并保护您的数据。
只需遍历 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;
}
}
【讨论】:
试试:
dgvNoCargadas[columns, index].ReadOnly = false;
【讨论】: