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

weirest thing going on with message box

Status
Not open for further replies.

jpack23

Programmer
Dec 15, 2004
82
US
have a very simple okonly messag box to be displayed, but I have to click the OK button twice to make it go way. I can see if flicker on the screen like it redrawn a just after I click the ok button the first time.

If I set a breakpoint on the line of code just after the message box I only have to click once. So when I step through code it only displays the box once, when I disable all breakpoints and run the app it looks like the message box pops up twice and I have to click twice to make it go away.

Thanks for you help
Joe
 

Is there some sort of loop or recursion or something that could be calling the code twice inadvertently?

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!
 
The message box is in a private function

Private Function CheckEmps
Select Case cboxEmps

Case is > 0
''lots of code
Case 0
''more ocde
Case Else
If mbooskipBox = False Then
If MsgBox("Please Choose Employee ", MsgBoxStyle.OkOnly) = MsgBoxResult.Ok Then
mbooskipBox = True
mintSi = 1
Else
mintSi = 1
End If
End If

Reurn False
End Select
End Function

This fuction called by the listview Item Selectionchanged event

Private Sub lvwForms_ItemSelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles lvwForms.ItemSelectionChanged
If mbooEmpsCheck = False Then
If CheckEmps() = True Then
Exit Sub
Else
lvwForms.SelectedItems.Clear()
mbooEmpsCheck = False
End If
End If
mbooskipBox = False
End Sub


I put a break point on the line after the message box, I run my app and make the box come up, I click on the ok button and the message box goes away and the breakpoint code is highlighted, I then click the green arrow and the code runs to completion - message box doesnt appear (dont have to click the ok button again)

so it appears that its working correctly when I step through code. When I disable the breakpoints or publish the app and it run the messagbox makes me click ok (or press enter) Twice
 

Check where you (re)populate and/or clear cboxEmps, tht's where you set it to -1 (I guess...)

also, in here:
Code:
If MsgBox("Please Choose Employee ", MsgBoxStyle.OkOnly) = MsgBoxResult.Ok Then
   mbooskipBox = True
   mintSi = 1[red]
Else
   mintSi = 1[/red]
End If
You never get to the RED portion of your code, you can only choose OK from your MsgBox. So - why have it in the code?

Have fun.

---- Andy
 

I believe it is happening when you clear the SelectedItems - lvwForms.SelectedItems.Clear() - this will cause the selected index to change, which will fire off the CheckEmps function again.


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!
 
Wouldn't lvwForms.SelectedItems.Clear() cause its ItemSelectionChanged event to fire a second time?
 
I really need to learn to hit the refresh button before posting a reply! :~/
 
jebenson - wish it was that simple. I know about the selected index changing because I clear it, so I check a boolean variable to see if the CheckEmps has already been run, if so then code skips over the call to CheckEmps.

If mbooEmpsCheck = False Then
If CheckEmps() = True Then
Exit Sub
Else
lvwForms.SelectedItems.Clear mbooEmpsCheck = False
End If
End If



andy- the red code I just put in trying to figure out why I can step through the code (F11) and it works fine but when I run the app I get that message box popping up another time after clicking the ok button.

Bottom line is I have a listview with icons and when the user selects an Icon I need the app to check to see if emp is signed in and if they arent then I need to pop up a reminder, clear the selected item and index (so the message box pops up again if they forget to sign in a second time)

appreciate you time, thanks

joe
 

Try running setting the boolean flag like this and see what happens:

mbooskipBox = True
lvwForms.SelectedItems.Clear()
mbooskipBox = False

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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top