Skip to main content
Sep 19, 2015

One of requests you could get to implement in an application is to know when a user selects an item in the Combobox editing control in a DataGridView.

ComboBox control on the from has the SelectedIndexChanged event. However, in the DataGridViewComboBox there is the DataGridView.EditingControlShowing event.

Here is the code example that demonstrates how to achieve this. Consider also, that this example shows you how to prevent firing multiple SelectedIndexChanged events.

private void dataGridView1_EditingControlShowing(object sender, 
                    DataGridViewEditingControlShowingEventArgs e)
{
    ComboBox cb = e.Control as ComboBox;
    if (cb != null)
    {
        // first remove event handler to keep from attaching multiple:
        cb.SelectedIndexChanged -= new EventHandler(cb_SelectedIndexChanged);
 
        // now attach the event handler
        cb.SelectedIndexChanged += new EventHandler(cb_SelectedIndexChanged);
    }
}
 
void cb_SelectedIndexChanged(object sender, EventArgs e)
{
    MessageBox.Show("Selected index changed");
}