2012-02-14 33 views
0

我使用使用gridViewProducts.Rows.Add(dViewRow);如何添加ComboBox到C#中的DataGridViewRow?

DataGridViewRow dViewRow = new DataGridViewRow();  
DataGridViewTextBoxCell Sno = new DataGridViewTextBoxCell();  
DataGridViewComboBoxCell dgCombo = new DataGridViewComboBoxCell(); 

dViewRow.Cells.Add(Sno); 
dViewRow.Cells.Add(dgCombo); 
dViewRow.Cells[0].Value = 1; 
dViewRow.Cells[1].Value = "ASP"; 

然後我綁定DataGridViewRow到主DataGrid代碼,但我收到以下錯誤:

System.ArgumentException:DatagridviewCombobox值無效

+0

使用模板列。 – 2012-02-14 06:09:14

+0

你有沒有附加到'ComboBoxColumn'的任何數據源?錯誤意味着值(ASP)對組合框不可用/有效。所以請添加相同的細節 – V4Vendetta 2012-02-14 06:13:12

回答

-1

用戶模板字段

<asp:TemplateField HeaderText="List"> 
        <ItemTemplate> 
         <asp:DropDownList ID="dlBox" runat="server"></asp:DropDownList> 
        </ItemTemplate> 
       </asp:TemplateField> 
+0

這是winform! – V4Vendetta 2012-02-14 06:11:57

+0

DropDownList在c#windows應用程序中不支持 – Prinsu 2012-02-14 06:15:58

相關問題