Search code examples
c#winformsbindingsource

Bind Combobox form LIST<> in datagirdview


How can i bind the combobox with LIST<> in datagridview . For Binding the 'Combobox' Here i am directly assign the value in binding source .

 programEntityBindingSource.DataSource = _Usercom.GetProgramName();

How can i do this


Solution

  • You have to run through the datagridview rows and bind it one by one as follows,

    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!
    }