[ACCEPTED]-How do I set up a DataGridView ComboBoxColumn with a different DataSource in each cell?-datagridview
Accepted answer
The following works for me:
DataGridViewComboBoxColumn newColumn = new DataGridViewComboBoxColumn();
newColumn.Name = "abc";
newColumn.DataSource = new string[] { "a", "b", "c" };
dataGridView1.Columns.Add(newColumn);
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 =
(DataGridViewComboBoxCell)(dataGridView1.Rows[row].Cells["abc"]);
cell.DataSource = new string[] { "f", "g" };
}
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.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.