Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / December 2006

Tip: Looking for answers? Try searching our database.

ComboBox.SelectedIndexChanged Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Calvin Willman - 12 Dec 2006 12:30 GMT
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?
AlBruAn - 14 Dec 2006 06:26 GMT
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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.