Search code examples
c#drop-down-menudatagridviewcombobox

Datagridview Combobox columns won't dropdown (C#)


I have a datagridview filled with 8 columns of comboboxes, and 32 rows.

    private void frm_Main_Load(object sender, EventArgs e)
    {
        // Make 32 rows total
        for (int i = 0; i <= 30; i++)
        {
            DataGridView1.Rows.Add();
        }
        PopulateComboBoxes();
    }

and I've also added some items to each of them. For some reason they won't drop down when I click them.

I have looked around, but nothing seems to work.

edit: It just adds each of the dropdown options in

    public void PopulateDropDowns()
    {
        //Get Errors
        DataSet Errors = SendQueryReturnDataSet("SELECT * FROM DB.Errors");
        DataTable dt_Errors = Errors.Tables[0];

        //Populate all Drop Downs
        for (int i = 0; i < dt_Errors.Rows.Count; i++)
        {
            for (int x = 0; x<8; x++)
            {
                for (int y = 0; y < 32; y++)
                {
                    (grid_Wafer.Rows[x].Cells[y] as DataGridViewComboBoxCell).Items.Add(dt_Errors.Rows[i][1].ToString());
                }
            }
        }

    }

Solution

  • private void Form1_Load(object sender, EventArgs e)
    {
        PopulateComboBoxes();
        // Make 32 rows total
        for (int i = 0; i <= 30; i++)
        {
            dataGridView1.Rows.Add();
        }
    }
    
    private void PopulateComboBoxes()
    {
        //for each column, set as combobox, then populate
        var cName = new DataGridViewComboBoxColumn();
        cName.Items.Add("John Galt");
        cName.Items.Add("Tim Duncan");
        cName.Items.Add("King Leonidas");
        var cAddress = new DataGridViewComboBoxColumn();
        cAddress.Items.Add("Main Street");
        cAddress.Items.Add("Broad Street");
        cAddress.Items.Add("Market Street");
    
        dataGridView1.Columns.Add(cName);
        dataGridView1.Columns.Add(cAddress);
    
    }