I've got a databound combobox on a usercontrol in a VSTO app. I want to
handle the selected index changed event display/hide some other controls on
the form, which seems to be working fine in it self... but when I click the
button to submit the form, it seems to fire again, and I get a null
exception on the selectedindex...
The same thing happens with a radio button changed event in that is fires or
executes when the button/form is submitted...
I only want these events to fire when the controls are changed... not when
the button is clicked?
Have you tried disabling the event handlers for the combobox and your radio
buttons?
You might try something similar to the following:
private void button1_Click(object sender, EventArgs e)
{
comboBox1.SelectedIndexChanged -= comboBox1_SelectedIndexChanged;
radioButton1.CheckedChanged -= radioButton1_CheckedChanged;
// Perform your save operation here
comboBox1.SelectedIndexChanged += new
EventHandler(comboBox1_SelectedIndexChanged);
radioButton1.CheckedChanged += new EventHandler(radioButton1_CheckedChanged);
}
HTH
Allen
> I've got a databound combobox on a usercontrol in a VSTO app. I want to
> handle the selected index changed event display/hide some other controls on
[quoted text clipped - 7 lines]
> I only want these events to fire when the controls are changed... not when
> the button is clicked?
Calvin Willman - 14 Dec 2006 08:13 GMT
Thanks Allen,
I thought of doing that, but found that just calling the Focus method on a
label, before disabling the button meant that focus wasn't automatically
passed to the radiobutton resulting in the SelectedIndexChanged event
getting fired... as so it seems to work ok.
Thanks again.
> Have you tried disabling the event handlers for the combobox and your
> radio
[quoted text clipped - 34 lines]
>> when
>> the button is clicked?