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 General / August 2006

Tip: Looking for answers? Try searching our database.

ComboBox.SelectedIndexChanged by user or code?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark Raishbrook - 25 Aug 2006 15:37 GMT
This is more of a grumble than a question really.

I have a config file that reads various settings into my app on start-up.
One of these settings sets the selected item in a combo box, which in turn
fires the combo's SelectedIndexChanged event, which in turn causes all hell
to break loose.

I realise I can add RemoveHandler/AddHandler code before/after the line that
reads this setting from the config file but, as the app grows, this sort of
redundant code replication is going to start to annoy me.

Wouldn't it be far better if .NET could make a distinction between the
selected index being changed in code and the selected index being changed by
the user? Couldn't we have something like a SelectedIndexUserChanged event as
well? This was available in VB6, after all (ListIndex and Click).
Bruce Wood - 25 Aug 2006 19:22 GMT
> This is more of a grumble than a question really.
>
[quoted text clipped - 11 lines]
> the user? Couldn't we have something like a SelectedIndexUserChanged event as
> well? This was available in VB6, after all (ListIndex and Click).

I solved this problem in each class with a single boolean flag,
something like

bool _updating;

It's usually set to false, unless I'm updating controls
programmatically:

this._updating = true;
try
{
   this.comboBox1.SelectedIndex = ... ;
   this.textBox1.Text = ... ;
   etc.
}
finally { this._updating = false; }

Then, in the event handlers:

private void comboBox1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
   if (!this._updating)
   {
       ... react to event ...
   }
}

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.