• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

Exposing a change event on a datagridview cell that is configured as a combobox

I have a datagridview that uses a drop down for one column. I want to capture the event where the user change the value in the drop down, but none of the supplied events appear to take effect until AFTER I leave the cell and move the focus somewhere else.

Is there a way to cast this cell to the specific cell type and raise an event that fires immediately when the combo value is changed?
1 Solution
       public Form1()
            dataGridView1.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dataGridView1_EditingControlShowing);

        void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
            if (dataGridView1.CurrentCell is DataGridViewComboBoxCell)
                ComboBox cmb = e.Control as ComboBox;
                cmb.SelectedIndexChanged -= new EventHandler(cmb_SelectedIndexChanged);
                cmb.SelectedIndexChanged += new EventHandler(cmb_SelectedIndexChanged);

        void cmb_SelectedIndexChanged(object sender, EventArgs e)
            ComboBox cmb = sender as ComboBox;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now