Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ComboBox and SelectedIndex Event...

Status
Not open for further replies.

TerDavis

Technical User
Sep 18, 2002
36
US
I have an combobox and created an SelectedIndex event that would do some things if the selected item in the combobox changes.

My question is this : I am also internally - setting the index of the selected item for the combobox in code,

FilterControl.CboSearchOption.SelectedIndex = 0;

And this fires my event for SelectedIndexChange.

I only want the SelectedIndexChange to fire if the index was changed by an USER using the application, and not when the code is setting the index.

I noticed that the textbox has an property, Modified, that is set when a USER modifies the text,but the combobox dosn't have this property.

How would I set up my event such that i can tell whether the index change was internal or external ?

 
The easiest way is to have a flag in your FilterControl class. Rather than using [tt]FilterControl.CboSearchOption.SelectedIndex = 0[/tt] I would create a property in the FilterControl class that would set the flag, set the SelectedIndex, then set the flag back. In your event handler for SelectIndexChanged, you'd not take action if the flag was set.

Something like:
Code:
public void SetSearchOptionIndex {
  set {
    bSearchOptionCodeChange = true;
    CboSearchOption.SelectedIndex = 0;
    bSearchOptionCodeChange = false;
  }
}[code]

In your event handler:
[code] ...
  if (!bSearchOptionCodeChange) {
    [COLOR=blue]whatever you do[/color]
  }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top