PC Review


Reply
Thread Tools Rate Thread

Capturing "validating" event in TextBox of form negates normal "esc key" action

 
 
Steve Roggow
Guest
Posts: n/a
 
      9th Dec 2003
I am using a form that contains a TextBox class object of
which I capture the Validating event. This form is shown
as a dialog box. The problem is this: A user enters
invalid characters into the TextBox object and then
changes his/her mind and hits the escape key. Normally,
the ShowDialog function returns as if the user pressed
the cancel button - and this is the desired action.
However, with "validating" captured, the system invokes
my validating code BEFORE anything else (that I can
determine). There is no way to know that the user is
wanting to simply leave, so I need to pop up another
dialog box that complains about the invalid entry and
from here, the user may exit the form. I tried capturing
the events: "Leave, Keydown, Keypressed", etc to see if
these get invoked before "Validating" and no-dice.

The lack of any other postings regarding this , what I
would consider a common problem, tells me that I have
probably overlooked something obvious ...

Thanks for any help!



 
Reply With Quote
 
 
 
 
Brian
Guest
Posts: n/a
 
      9th Dec 2003
You can give this a try:

Dim check As Boolean = False

Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
If check Then
MessageBox.Show("Validating")
End If
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs)Handles
check = True
TextBox1_Validating(sender, New
System.ComponentModel.CancelEventArgs())
check = False
End Sub


Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Escape Then Close()
End Sub

Basically, you're calling the Validating event when the text changes. All
other calls will be rejected.


"Steve Roggow" <(E-Mail Removed)> wrote in message
news:1013f01c3be5e$a23b3ba0$(E-Mail Removed)...
> I am using a form that contains a TextBox class object of
> which I capture the Validating event. This form is shown
> as a dialog box. The problem is this: A user enters
> invalid characters into the TextBox object and then
> changes his/her mind and hits the escape key. Normally,
> the ShowDialog function returns as if the user pressed
> the cancel button - and this is the desired action.
> However, with "validating" captured, the system invokes
> my validating code BEFORE anything else (that I can
> determine). There is no way to know that the user is
> wanting to simply leave, so I need to pop up another
> dialog box that complains about the invalid entry and
> from here, the user may exit the form. I tried capturing
> the events: "Leave, Keydown, Keypressed", etc to see if
> these get invoked before "Validating" and no-dice.
>
> The lack of any other postings regarding this , what I
> would consider a common problem, tells me that I have
> probably overlooked something obvious ...
>
> Thanks for any help!
>
>
>



 
Reply With Quote
 
Steve
Guest
Posts: n/a
 
      9th Dec 2003
Brian,

Thanks for taking the time to reply.. Yes, your
suggestion may be a valid solution in VB (I am using C#)
and logically, your code makes sense. I have found in C#
that the escape key seems to bypass many of
the "expected" invocations such as the key down event. In
my case, the form with the text box in it simply returns
if as a person hit the cancel key. However, not before
the "validating" event is invoked! After posting this
morning, I continued working the problem and finally just
left the validating event out and used the "Leave" event
for the text box instead. I did my validating in the
Leave event handler. This causes the expected result of
exiting unconditionally when the user presses the escape
key, but this created a problem if the user clicked on
the cancel button - of course the "Leave" event handler
was called here also. I fixed this problem by checking
(within my "Leave event" handler) to see if the cancel
button had the focus and if it did, simply returned
without validating! Boy, some of the obfuscated things
that one has to do!

Thanks again for the reply.
>-----Original Message-----
>You can give this a try:
>
>Dim check As Boolean = False
>
> Private Sub TextBox1_Validating(ByVal sender As

Object, ByVal e As
>System.ComponentModel.CancelEventArgs) Handles

TextBox1.Validating
> If check Then
> MessageBox.Show("Validating")
> End If
> End Sub
>
>Private Sub TextBox1_TextChanged(ByVal sender As Object,

ByVal e As
>System.EventArgs)Handles
> check = True
> TextBox1_Validating(sender, New
>System.ComponentModel.CancelEventArgs())
> check = False
> End Sub
>
>
> Private Sub TextBox1_KeyDown(ByVal sender As Object,

ByVal e As
>System.Windows.Forms.KeyEventArgs) Handles

TextBox1.KeyDown
> If e.KeyCode = Keys.Escape Then Close()
> End Sub
>
>Basically, you're calling the Validating event when the

text changes. All
>other calls will be rejected.
>
>
>"Steve Roggow"

<(E-Mail Removed)> wrote in
message
>news:1013f01c3be5e$a23b3ba0$(E-Mail Removed)...
>> I am using a form that contains a TextBox class object

of
>> which I capture the Validating event. This form is

shown
>> as a dialog box. The problem is this: A user enters
>> invalid characters into the TextBox object and then
>> changes his/her mind and hits the escape key. Normally,
>> the ShowDialog function returns as if the user pressed
>> the cancel button - and this is the desired action.
>> However, with "validating" captured, the system invokes
>> my validating code BEFORE anything else (that I can
>> determine). There is no way to know that the user is
>> wanting to simply leave, so I need to pop up another
>> dialog box that complains about the invalid entry and
>> from here, the user may exit the form. I tried

capturing
>> the events: "Leave, Keydown, Keypressed", etc to see if
>> these get invoked before "Validating" and no-dice.
>>
>> The lack of any other postings regarding this , what I
>> would consider a common problem, tells me that I have
>> probably overlooked something obvious ...
>>
>> Thanks for any help!
>>
>>
>>

>
>
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Click the star to watch this topic] "bollywood actress""bollywood wallpapers" "bollywood news" "bollywood movies" "bollywood videosongs" "bollywood masala" "bollywood" "b Naeem Microsoft C# .NET 0 4th Jan 2010 07:57 AM
Field Names: "LongName", "ShortName", "Code", "Description","Comments" PeteCresswell Microsoft Access 2 26th Feb 2009 12:41 AM
"Rule based design" or "event-condition-action" pattern? feng Microsoft VB .NET 1 28th Feb 2005 10:18 AM
Capturing a "Move" or "Copy" Event Neil Dittmar Microsoft Outlook Form Programming 1 27th Jul 2004 03:03 PM
<FORM METHOD="post" onSubmit="return fieldcheck()" name="orientation" action="http://ws-kitty.BU.edu/AT/survey/orientation/script/write.asp" language="JavaScript"> Joeyej Microsoft ASP .NET 0 4th Jun 2004 09:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:06 PM.