Solved

Stopping the SelectedIndexChanged Event

Posted on 2007-03-23
1
252 Views
Last Modified: 2008-01-09
I am updating a combo box during a form load which is firing off the SelectedIndexChanged event, but I do not want it to fire this event at this stage. Is there a way to stop this?

Regards,

Josh
0
Comment
Question by:supersuny2k
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 17

Accepted Solution

by:
ZeonFlash earned 500 total points
ID: 18779401
There are several methods you can use to get around this problem.

1.  You can always remove the event handler and add it back again after loading.  This isn't necessarily the "best" way of doing things, considering the problem that occurs if the loading stops before adding the event handler back.

RemoveHandler Combobox1.SelectedIndexChanged, AddressOf Combobox1_SelectedIndexChanged
.
.
AddHandler Combobox1.SelectedIndexChanged, AddressOf Combobox1_SelectedIndexChanged

2.  You can create a class variable along the lines of "IsLoading" that you set to True while the form is loading and False when it's done.  Then at the top of your SelectedIndexChanged event, you check the flag and continue on if not loading:

     Private IsLoading As Boolean = False

      Private Sub Combobox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Combobox1.SelectedIndexChanged
     If IsLoading Then Exit Sub
      .
      .

            End Sub
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question