来自LIST的Bind Combobox<>在datagridview中

时间:2013-05-02 05:23:50

标签: c# winforms bindingsource

如何将组合框与LIST<>结合?在datagridview中。绑定'Combobox' 在这里,我直接在绑定源中分配值。

 programEntityBindingSource.DataSource = _Usercom.GetProgramName();

我该怎么做

1 个答案:

答案 0 :(得分:1)

您必须遍历datagridview行并按如下方式将其逐个绑定,

foreach (DataGridViewRow row in myDataGridViewProducts.Rows) 
{
        DataGridViewComboBoxCell cell =DataGridViewComboBoxCell)row.Cells("myProductCol");
    cell.DataSource = _Usercom.GetProgramName();
    cell.DataPropertyName = "ProgramName";        
    cell.DisplayMember = "Name";
    cell.ValueMember = "Self"; // key to getting the databinding to work
    // no need to set cell.Value anymore!
}