DataGridView Combo Box problem


In My application I have a DataGridView with 2 combo boxes.The First ComboBox contains all the countries
The Second Combo Box contains all the States corresponding to the country selected in First Combo

I have n rows in the DataGridView

I am able to do the above but the problem is when the second combo box is populated on selection change, it happens for all the rows and not the current row.

My Query is How do we set the DataSource of the ComboBox at the cell Level..Right now i am setting this at the DataGridViewcolumn Level

Thanks in advance



  • Dear Arvind,

    Try this Solution ..

    /// return New Cell with new DataSource
    private DataGridViewComboBoxCell GetCell(int rowIndex)
    DataGridViewComboBoxCell c = new DataGridViewComboBoxCell();
    int id = Convert.ToInt32(grd.Rows[rowIndex].Cells[2].Value);
    c.ValueMember = "ValueMember";
    c.DisplayMember = "DisplayMember";
    c.DataSource = dt;
    return c;

    ///RowsAdded Event
    private void grd_(object sender, DataGridViewRowsAddedEventArgs e)
    foreach (DataGridViewRow row in grd.Rows)
    if (row.IsNewRow) continue;
    row.Cells[3] = GetCell(row.Index);

    ///CellEndEdit Event
    private void grd_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    if (e.ColumnIndex == 2)
    grd[3, e.RowIndex].Value = null;
    grd[3, e.RowIndex] = GetCell(e.RowIndex);
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion