Click event gets lost when call MSGBOX in leave event

T

Tom

I have a VB .NET application that has a text box with the
following code to handle the leave event.

Private Sub txtIDiscountRate_TextChanged(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
txtIDiscountRate.Leave
If txtIDiscountRate.Text.Trim <> "" AndAlso _
MsgBox("Are you sure you want to use a non-
default discount rate?", MsgBoxStyle.OKCancel) _
= MsgBoxResult.Cancel Then
'txtIDiscountRate.Text = ""
End If
End Sub

There are also several buttons on the same dialog box as
the text box. The problem occurs when I have focus on
the text box and then click on a button. If the call to
MSGBOX gets executed (because there is text in the
textbox) then the button click event never gets called.
(I have a breakpoint set on the first line of the button
click event routine.) I've checked (by commenting out
code) that it is definitely the call to MSGBOX which
makes the call to the button click routine get lost.

Suggestions please. Thanks
 
G

Guest

You have it in the Text Changed Event. Change it to TextBox Lost Focus. See
below:

Lost Focus Event:
--------------------

Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.LostFocus
End Sub

You are using Text Changed/Lost Focus Events. See below:
------------------------------------------------------

Private Sub txtIDiscountRate_TextChanged(ByVal sender ..., but you use
'Handles TextBox.LostFocus

The above is a mistake.

Remember to use 'MessageBox.Show(...) now that you are you are using VB.NET.
Yes, of course you can still use the old VB 6 way.
 
G

Guest

You have it in the Text Changed Event. Change it to TextBox Lost Focus. See
below:

Lost Focus Event:
--------------------

Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.LostFocus
End Sub

You are using Text Changed/Lost Focus Events. See below:
------------------------------------------------------

Private Sub txtIDiscountRate_TextChanged(ByVal sender ..., but you use
'Handles TextBox.LostFocus

The above is a mistake.

Remember to use 'MessageBox.Show(...) now that you are you are using VB.NET.
Yes, of course you can still use the old VB 6 way.
 
G

Guest

You have it in the Text Changed Event. Change it to TextBox Lost Focus. See
below:

Lost Focus Event:
--------------------

Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.LostFocus
End Sub

You are using Text Changed/Lost Focus Events. See below:
------------------------------------------------------

Private Sub txtIDiscountRate_TextChanged(ByVal sender ..., but you use
'Handles TextBox.LostFocus

The above is a mistake.

Remember to use 'MessageBox.Show(...) now that you are you are using VB.NET.
Yes, of course you can still use the old VB 6 way.
 

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