RazorEater
RazorEater

Reputation: 265

new items in DataGridViewComboBoxCell not showing

I'm using a Datagridview, partly filled by a datasource, by setting DataPropertyNames. Partly filled by me in the code. I have a DataGridViewComboBoxColumn where cells should be filled when i click the button next to it. Clicking the button fills the Items of the DataGridViewComboBoxCell, but if i click on the ComboBox, i can't open it to select a value.

(At the end of the function i change a columnvalue to x as a test, this works fine...)

Code:

//add the combobox column
DataGridViewComboBoxColumn cellcol = new DataGridViewComboBoxColumn();
cellcol.Name = "Cell";
cellcol.ReadOnly = false;
dataGridView1.Columns.Add(cellcol);

//method that gets called when the button is clicked
private void getAllCells(List<ComponentRow> componentRows, int i)
        {

            //show all cells
            CellFilter cf = new CellFilter();
            cf.customerNr = libraryNr;
            Cell[] cells = Service.Instance.Client.queryCells(cf, new QueryParam());
            foreach (Cell c in cells)
            {
                ((DataGridViewComboBoxCell)dataGridView1["Cell", i]).Items.Add(cells[0].cell_name);
            }
            cellsShownForComponents[i] = ShowedCells.ALL;
            ((DataGridViewTextBoxCell)dataGridView1["variants", i]).Value = "x";
        }

Upvotes: 2

Views: 2685

Answers (1)

RazorEater
RazorEater

Reputation: 265

I'll answer my own question. The problem was that my datagridview was readonly. readonly comboboxcolumns can't be opened. I fixed it this way: for the datagridview

ReadOnly = false

for my comboboxcolumn

ReadOnly = false 

for every other column users shouldn't be able to edit

ReadOnly = true 

Upvotes: 5

Related Questions