2014-11-14 166 views

回答

3

先刪除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; 
      } 

     } 
+0

這工作,如果我把我的datagridview在readOnly = true;然後用row.Cells [2] .ReadOnly = false修改單元格。它有效,但爲什麼它在這裏工作,而不是當我做相反的事情時? –

+1

因爲當你讓dgv只讀爲真時,它不是檢查子屬性意味着單元格 –

0

嘗試:

dgvNoCargadas[columns, index].ReadOnly = false; 
+0

沒有隊友並沒有工作,這是同我嘗試但diferent sintaxis。 –

0

爲只讀您可以修改該列中的每個單元只有在單元格的值不等於空或字符串.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; 
    } 
} 
0
For Each row As DataGridViewRow In DataGridView1.Rows 
     row.Cells('Cellnumber').ReadOnly = False 
    Next 
相關問題