Textbox validating event in vb net

Rated 3.88/5 based on 642 customer reviews

I have a form w/ a textbox and Cancel button on it. When I click on the cancel button it doesn't even get to the cancel.click event until AFTER it has done the validating. As far as the original validation issue, I started a new project (VB2005) and tried your approach It works except that pressing the Esc key still causes the validation event to fire. According to the documentation: "The cancel button for a form is the button control that is clicked whenever the user presses the ESC key." Which says to me the behavior s/b the same! Validating If Not mbln Cancel Then Dim dte Date As Date Time If Date Time. Also note that the "trick" to closing the form is not keeping a seperate "canceling" flag, but to put "e.cancel=False" in the forms closing event.

I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. I am going to start a new thread - calling it a bug and see what happens. Down (Down Arrow) and some how (and I never figured this one out) the next control in the tab order, regardless of the Tab Stop property, got focus. Causes Validation = False Public Class Form1 Private mbln Cancel As Boolean Private Sub Text Box1_Validating(By Val sender As Object, By Val e As System. -- Terry "Al Reid" wrote: Terry, I tried the same scenario in VB6 and found that it works the way one would expect AND there is no need for the m Cancel flag either.

Length I guess I'm going to have to start with a new project and try it.

Its only because of the messagebox that you need to keep the flag.

Close() End Sub Private Sub Text Box1_Validating(By Val sender As Object, By Val e As System. Somewhere in all of that, something must be getting crossed up. For example, I have another application that uses a wedge type barcode reader. Maybe you should be using the Key Down event instead of the Key Press event. here is a line copied from the documentation: "The Key Press event is not raised by noncharacter keys; however, the noncharacter keys do raise the Key Down and Key Up events." My guess is that the gun is sending some noncharacter data to you.

The form's Key Preview is set to True so that I can handle key events on the form... If I connect a gun type, the program fails and the cursor jumps to a text box that has it's Tab Stop property set to False. Print in the Form's Keypress event all three methods display the exact same key codes. -- Al Reid "Terry" Hi again Al, On the barcode reader problem.

Then in the btn Cancel_click event, either set a module level variable like m Canceling to True and then in the validating event ... It doesn't need to be validated because the user is exiting. Length Yes, closing the form causes 'validating' to take place. Close() End Sub Private Sub Text Box1_Validating(By Val sender As Object, By Val e As System. I am going to start a new thread - calling it a bug and see what happens. Down (Down Arrow) and some how (and I never figured this one out) the next control in the tab order, regardless of the Tab Stop property, got focus. Cancel = True End If End If End Sub Hi Al, Nearly 40 years for me since my first college FORTRAN IV class! Well, one of the keys you would not see in either the keypress or keydown events is the tab key, which of course will move the focus.

textbox validating event in vb net-90

textbox validating event in vb net-28

I don't want it to be since they are exiting the screen the validation doesn't have to be done. It doesn't need to be validated because the user is exiting. As far as the original validation issue, I started a new project (VB2005) and tried your approach It works except that pressing Esc key still causes the validation event to fire. -- Al Reid "Terry" Hi Al, There is another property at the form level that affects how this stuff works - Auto Validate.

I reprogrammed the device to only send the CR and now the problem is solved. I have come to the belief that the problem we are seeing with the escape key is a bug. Cancel = True End If End If End Sub Private Sub Button1_Click(By Val sender As System. I just don't know what key code combination could direct focus to a text box control that should never receive focus since the Tab Stop property is false and there is no other code that sets focus to the textbox. Also in the docs on Key Down there is a mention of "Is Input Key" which I will have to look into. Hi Al, Don't know if you have been following the thread I started about the escape key "bug", but if you search this community for "Cancel Button vs Escape Key", you can see the result including the work around for the escape key.

Down (Down Arrow) and some how (and I never figured this one out) the next control in the tab order, regardless of the Tab Stop property, got focus. Causes Validation = False Public Class Form1 Private mbln Cancel As Boolean Private Sub Text Box1_Validating(By Val sender As Object, By Val e As System. -- Al Reid "Terry" Hi Al, There is another property at the form level that affects how this stuff works - Auto Validate. To Short Date String Else Msg Box("Please enter a valid date.") e. As far as the 'gun', it may be better to write a console app. -- Terry Terry, I guess we have a similar background. I don't do anything with the barcode data in the Key Press event. I guess I could inspect the data in the Key Down event to see if there is a difference. -- Al Reid "Terry" news:78**********************************@microsof .. I am new to VB comming from VB6, but that was also the case in VB6.

My final solution, unless someone has a better suggestion, is to change the Validating event to the Leave event and detecting whether the cancel button had been clicked in the Leave event and exiting if it was. I just don't know what key code combination could direct focus to a text box control that should never receive focus since the Tab Stop property is false and there is no other code that sets focus to the textbox. Maybe you should be using the Key Down event instead of the Key Press event. here is a line copied from the documentation: "The Key Press event is not raised by noncharacter keys; however, the noncharacter keys do raise the Key Down and Key Up events." My guess is that the gun is sending some noncharacter data to you. Why it would stop on a textbox with tabstop property set to False - I have no idea, unless it is a behavior of the container its in.

If I hit the escape, the validation event fires and since the m Canceling is not True, the validation error gets displayed before the form closes. As far as the 'gun', it may be better to write a console app. -- Terry "Al Reid" wrote: Terry, I guess we have a similar background. I don't do anything with the barcode data in the Key Press event. I guess I could inspect the data in the Key Down event to see if there is a difference. -- Al Reid "Terry" Hi again Al, On the barcode reader problem. -- Al Reid "Terry" Hi Al, Nearly 40 years for me since my first college FORTRAN IV class! Well, one of the keys you would not see in either the keypress or keydown events is the tab key, which of course will move the focus.

Leave a Reply