Prevent a combo box SelectedIndexChanged event firing multiple tim

G

Guest

I am working on a form where the user select a value from a combo box and
depending on his selection a popup window display, asking for more
information.

My problem is that this popup is displayed twice when the user makes the
selection. Another problem is that this combo box is on a multi tab page and
when the user selects the tab for the first time the combo is on, the popup
is also displayed twice.

How can I get the event to only fire once and only when the user selects an
item in the combo box?

Thanks in advance for your help,

Johannes
 
S

Sijin Joseph

Hey Johannes,

I think it would be a better idea for you to explicilty check if you are
already showing a popup before showing the popup. That would be easier
than making the selectionchanged event firing once.

Below is some sample code you could use

//On the selection change event

if(_alreadyShowingPopup)
return;
else
_alreadyShowingPopup = true;
ShowPopup();

Hope that helps.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
 
J

Johannes Vorster

Hi

This will defenitely help.

On what event will I then clear the _alreadyShowingPopup variable, so its
ready for the next round of selection change events.

Johannes
 
G

Guest

Try checking for focus... This would indicate the user is on the combo via
the keyboard, or the combo was clicked with the mouse.

Of course you should probably set focus to something else when changing this
valud programatically.

You could also use the comboBox1.Tag to determine if it's code changing the
value... if it's code say Tag = "Code", then ignore the popup.

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if(comboBox1.Focused)
MessageBox.Show("Sel index changed");
}


Hope this helps....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top