[ACCEPTED]-How do I set up a DataGridView ComboBoxColumn with a different DataSource in each cell?-datagridview

Accepted answer
Score: 21

The following works for me:

DataGridViewComboBoxColumn newColumn = new DataGridViewComboBoxColumn();
newColumn.Name = "abc";
newColumn.DataSource = new string[] { "a", "b", "c" };

foreach (DataGridViewRow row in dataGridView1.Rows)
    DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)(row.Cells["abc"]);
    cell.DataSource = new string[] { "a", "c" };

You could also 1 try (this also works for me):

for (int row = 0; row < dataGridView1.Rows.Count; row++)
   DataGridViewComboBoxCell cell = 
   cell.DataSource = new string[] { "f", "g" };
Score: 0

Another option is to try databinding on 5 the row level. Try using the event OnRowDataBound 4 event. Then you can programatically set 3 what is in the combo box based on the contents 2 of that row.

Of course, this presumes you 1 are databinding you grid.

More Related questions