I have a DataGridView
which has a ComboBoxColumn
I added in the form designer. In my code I want to add rows which each have individual ComboBoxCell
's. This is due to each row having different values in the ComboBoxes.
I have tried adding DataGridViewComboBoxCell
items as shown below and also by creating a DataTable
and binding it to the DataGridViewComboBoxCell
. When I run the program, I can see the rows and ComboBoxes, but when I attempt to click the boxes, no items are displayed.
DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell();
DataGridViewComboBoxCell cell2 = new DataGridViewComboBoxCell();
cell.Items.Add("Item1");
cell.Items.Add("Item2");
cell.Items.Add("Item3");
cell2.Items.Add("Item4");
cell2.Items.Add("Item5");
cell2.Items.Add("Item6");
DataGridViewRow row = new DataGridViewRow();
DataGridViewRow row1 = new DataGridViewRow();
row.Cells.Add(cell);
row1.Cells.Add(cell2);
dataGridView1.Rows.Clear();
dataGridView1.Rows.Add(row);
dataGridView1.Rows.Add(row1);
dataGridView1.Refresh();
I can't really seem to find a solution in other posts. Can anyone help get the items to display?
EDIT: The DataGridView
has been set to disable editing, which I have discovered stops me from viewing the ComboBox
items. In the real program there are other columns, and it is meant to be read only which is why I disabled editing. I would still like the user to be able to click and view the ComboBox
items.