我有一個datagrid視圖,屬性爲readonly = true;但我想設置一些細胞可編輯的,我嘗試用下面的代碼來做到這一點:使datagridview c中的一個單元格可編輯#
this.dgvNoCargadas.Rows[index].Cells[columns].ReadOnly = false;
但我不能修改網格,人有什麼想法?
我有一個datagrid視圖,屬性爲readonly = true;但我想設置一些細胞可編輯的,我嘗試用下面的代碼來做到這一點:使datagridview c中的一個單元格可編輯#
this.dgvNoCargadas.Rows[index].Cells[columns].ReadOnly = false;
但我不能修改網格,人有什麼想法?
先刪除DGV只讀真 然後
foreach (DataGridViewRow row in DataGridView1.Rows)
{
if (// condition for true)
{
row.Cells[2].ReadOnly = true;
}
else// condition for fals)
{
row.Cells[2].ReadOnly = false;
}
}
嘗試:
dgvNoCargadas[columns, index].ReadOnly = false;
沒有隊友並沒有工作,這是同我嘗試但diferent sintaxis。 –
爲只讀您可以修改該列中的每個單元只有在單元格的值不等於空或字符串.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;
}
}
For Each row As DataGridViewRow In DataGridView1.Rows
row.Cells('Cellnumber').ReadOnly = False
Next
這工作,如果我把我的datagridview在readOnly = true;然後用row.Cells [2] .ReadOnly = false修改單元格。它有效,但爲什麼它在這裏工作,而不是當我做相反的事情時? –
因爲當你讓dgv只讀爲真時,它不是檢查子屬性意味着單元格 –