簡體   English   中英

在datagridview中使一個單元格可編輯c#

[英]Make one cell editable in datagridview c#

我有一個datagrid視圖,其屬性為readonly = true; 但我想設置一些單元格可編輯,我嘗試用下一個代碼執行此操作:

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

但我無法修改網格,有人有任何想法?

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

嘗試:

dgvNoCargadas[columns, index].ReadOnly = false;

您可以將列中的每個單元格修改為只讀,其中單元格值不等於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;
     }
}
    For Each row As DataGridViewRow In DataGridView1.Rows
        row.Cells('Cellnumber').ReadOnly = False
    Next

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM