I know this may be a duplicate, but I have not been able to find a solution that works. I have a datagridview that has a combo box column. When I don't try to set the value of the combo box column, all is fine (i.e., the combo box column is populating). When I try to set the value, I get the infamous "DataGridViewComboBoxCell value is not valid" error. Here is my code:
//Retrieve Data
System.Data.DataRowCollection DR1 = GetData(constants.SQL_1);
System.Data.DataRowCollection DR2 = GetData(constants.SQL_2);
//Populate list for combo box column
List<string> list2 = new List<string>();
foreach (System.Data.DataRow DR in DR2)
list2 .Add(DR["fieldname"].ToString().Trim());
//Set datasource of combo box column
DataGridViewComboBoxColumn cmb = (DataGridViewComboBoxColumn)dgv.Columns["comboboxcolumnname"];
cmb.ValueType = typeof(string);
cmb.DataSource = list2 ;
//Populate Data Grid View
foreach (System.Data.DataRow DR in DR1)
{
DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell();
cell.Value = DR["fieldname"].ToString();
DataGridViewRow row = new DataGridViewRow();
row.Cells.Add(cell);
dgv.Rows.Add(row);
}
How do I set the value of the combo box??