簡體   English   中英

Datagridview僅在某些行中組合

[英]Datagridview comboboxes only in some rows

在我的winforms應用程序中,我有一個DataGridView ,其中一行使用DataGridViewComboBoxColumn控件,以便它包含此列的組合框。

是否有可能以其他方式以編程方式替換該列中的某些組合框? (例如標簽上寫着“不適用”)。 我只想在某些行中使用組合框。

您應該使用DataGridViewComboBoxCell屬性而不是DataGridViewComboBoxColumn屬性。 如下所示:

for(int intCount=0;intCount<dgv.Rows.Count;intCount++)
{
   if(intCount % 2 == 0)  //Your own condition here
   {
      DataGridViewComboBoxCell cmb = new DataGridViewComboBoxCell();
      //cmb.Value   // assign values in the combobox
      dgv[0,intCount] = cmb;
   }
   else
   {
      DataGridViewTextBoxCell txt = new DataGridViewTextBoxCell();
      txt.Value = "n/a";
      dgv[0,intCount] = txt;
   }
}

在上面的示例中,我在第一列中分配Individual單元屬性。

暫無
暫無

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

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