469,365 Members | 1,889 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,365 developers. It's quick & easy.

Any Method to Raise a Validating Event to other control?

Hi All,
I am writing a simple win form which contains a button, when user click the
button i want to validate all the other textbox and see if there is anything
goes wrong

may i know how can i trigger the validating event for all text box?

thx and regard,s
Norton
Nov 21 '05 #1
5 8871
How many textboxes & what are you validating against?
Nov 21 '05 #2
Norton,
I got the following tip from "Windows Forms Programming in C#" by Chris
Sells, from Addison Wesley.

Within your "Accept" button click handler (the "save" button) process each
control that CausesValidation to ensure that they are all valid...

Something like:

For Each control As control In Me.Controls
If control.CausesValidation Then
control.Focus()
If Not Me.Validate() Then
Me.DialogResult = DialogResult.None
Exit For
End If
End If
Next

Note this version does not validate controls nested within other container
controls, such as GroupBoxes, I would include the above in a recursive
subroutine.

The above code will cause the Validating event for each of your controls to
be raised, ensuring that all the controls get validated, before the dialog
is closed or the data is saved...

Hope this helps
Jay
"norton" <no********@hotmail.com> wrote in message
news:eB*************@tk2msftngp13.phx.gbl...
Hi All,
I am writing a simple win form which contains a button, when user click
the
button i want to validate all the other textbox and see if there is
anything
goes wrong

may i know how can i trigger the validating event for all text box?

thx and regard,s
Norton

Nov 21 '05 #3
Norton,

It sounds for me as a horse behind the car.

How can something be wrong in a textbox when you use correct the validating
event.
(Assuming you are not placing conflicting date in there by the program)

It will be executed as that control looses the focus.

What is it I miss?

Cor
Nov 21 '05 #4
"Cor Ligthert" <no************@planet.nl> wrote in message
news:uo**************@TK2MSFTNGP09.phx.gbl...
.. . .
How can something be wrong in a textbox when you use correct the
validating event. .. . . It will be executed as that control looses the focus.
What is it I miss?


The User doesn't /have/ to Enter and Leave every control before
clicking the button ... Devilish things, these mouses .. er .. mice? ;-)

HTH,
Phill W.
Nov 21 '05 #5
Phill,

Now I understood you, in fact do you want to check if they are not empty?

However you can in my opinion for ever do (not tested)

sub ButtonClick event
textbox1_validating(textbox1,nothing)
textbox2_validating(textbox2,nothing)
etc.
end sub

As alternative for the already supplied options, while not knowing what
actions you take because of validationg errors.

Cor
Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Fábio Prado | last post: by
12 posts views Thread by Vittorio Pavesi | last post: by
2 posts views Thread by Chris Dunaway | last post: by
reply views Thread by Gary Shell | last post: by
5 posts views Thread by Ian Jewitt | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.