miso-aa6

Hi everyone.

I have a datagridview with 5 columns. the 2nd column is of combobox type. I want to capture an event in which if the selected item or index of the combobox column is changed, a messagebox is displayed. How can I add the event

Thanks


Re: Windows Forms General HOW TO GET AN EVENT FOR DATAGRIDVIEWCOMBOBOXCOLUMN CONTROL

timvw

You can subscribe to the EditingControlShowing event, the EvenArgs subclass in that event has a property Control which is the combobox... .. (and i've seen a couple of people doing the same via the CellEnter event)





Re: Windows Forms General HOW TO GET AN EVENT FOR DATAGRIDVIEWCOMBOBOXCOLUMN CONTROL

Mahmudmia

(1) In EditingControlShowing event handler of the gridview -

ComboBox cb = (ComboBox) e.Control;

(2) then hook the event that you wish to handle...

cb.SelectedIndexChanged -= new EventHandler(cb_SelectedIndexChanged);

cb.SelectedIndexChanged += new EventHandler(cb_SelectedIndexChanged);

(3) Now write the event handler -

void cb_SelectedIndexChanged(object sender, EventArgs e)

{

// do whatever you want to do...

}





Re: Windows Forms General HOW TO GET AN EVENT FOR DATAGRIDVIEWCOMBOBOXCOLUMN CONTROL

miso-aa6

where would I type the code from your step 2 is it on the EditingControlShowing Event
do i have to modify the designer class also

Thanks






Re: Windows Forms General HOW TO GET AN EVENT FOR DATAGRIDVIEWCOMBOBOXCOLUMN CONTROL

miso-aa6

I've tried the solution. But nothing happens in the event handle for selectedindexchanged.

I wrote MessageBox.Show("Sample"); so that everytime I click on the combobox, the messagebox will show. But it didn't work






Re: Windows Forms General HOW TO GET AN EVENT FOR DATAGRIDVIEWCOMBOBOXCOLUMN CONTROL

timvw

I presume that you want the SelectionChangeCommitted event instead (which fires as soon as the user chooses something, and the Selected*Changed only after the focus has changed)