2012-12-08 31 views
0

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

是否有可能以其他方式編程替換該列中的某些組合框? (例如標籤上寫着「n/a」)。我只想要某些行中的組合框。

+0

儘管這種類型的功能是可能的(將標籤放置在某些行中而不是其他標籤中),但性能影響很大。是否可以接受一個解決方案,該解決方案只是將添加到顯示值爲「N/A」的列表項目中的附加項添加到「N/A」中? –

回答

2

您應該使用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; 
    } 
} 

在上面的例子中,我分配了第一列中的單個單元格屬性。