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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

msgbox for onclick change event for combo box

Status
Not open for further replies.

Shift838

IS-IT--Management
Jan 27, 2003
987
0
0
US
I am having an issue getting a yes/no box to work correctly when the selected item is changed. the issue i'm having is that it fires the event as soon as the form loads up as well as when it is an item is chosen from the drop down.

The combo box has 6 items in it that is populated on the properties of the item, not programatically.

Code:
Private Sub cmbJoinFarm_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbJoinFarm.SelectedIndexChanged
        If MsgBox("You have selected to join the " & cmbJoinFarm.SelectedItem & ".  Continue to join server to this farm?", MsgBoxStyle.YesNo) = vbNo Then
            MsgBox("Select correct farm and click Execute or exit program.")
        End If
    End Sub
 

At the top of your form's code, in the Declarations section, create a global Boolean variable:

Code:
Dim bFormLoading As Boolean

Then in the Form_Load event code, do this:

Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    bFormLoading = True

    'Form_Load code here

    bFormLoading = False

End Sub

Make sure that setting the value of bFormLoading is the very first and very last line of code in the event handler.

Finally, in the event with the MessageBox:

Code:
Private Sub cmbJoinFarm_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbJoinFarm.SelectedIndexChanged

    [red]If Not bFormLoading Then[/red]
        If MsgBox("You have selected to join the " & cmbJoinFarm.SelectedItem & ".  Continue to join server to this farm?", MsgBoxStyle.YesNo) = vbNo Then
            MsgBox("Select correct farm and click Execute or exit program.")
        End If
    [red]End If[/red]
End Sub

Now your MessageBox won't pop up while the form is loading.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thank you, worked like a dream.

Also found out mine would work, but I was actually setting a selecteditem in the form load on the combo box. to say "Select an option" and that is what was throwing it. I chose to do that programmatically because I did not see a selecton on the combo box properties for which item to use as a default selection.

Yours works great.

thanks,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top