[英]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.