Home All Groups Group Topic Archive Search About

Call control's event from a collection

Author
12 Apr 2006 8:38 PM
Bryan
I pass my form's collection of controls to a public sub in a module
that loops through and checks for any ErrorProvider text.  The sub
returns all the ErrorProvider strings that were found for display in a
msgbox to let the user know that there were data errors found.  This
works great, however, sometimes a user does not ever enter a certain
control, therefore that control's validating event is never called, so
my Error collecting sub will not return anything for this control.  I
need to be able to loop through all controls on a form and call each
control's validating event.  I need this code to be reusable for
multiple forms.  Any suggestions.

This does not work:

Public Function CallEventOfCtrl( Controls as controlcollection) as
string
for each c as control in Controls
     c.Validated
     'or
     call c.validated
next
End function

Author
12 Apr 2006 9:24 PM
Ken Halter
Show quote Hide quote
"Bryan" <bryanv***@gmail.com> wrote in message
news:1144874320.802186.62810@g10g2000cwb.googlegroups.com...
>I pass my form's collection of controls to a public sub in a module
> that loops through and checks for any ErrorProvider text.  The sub
> returns all the ErrorProvider strings that were found for display in a
> msgbox to let the user know that there were data errors found.  This
> works great, however, sometimes a user does not ever enter a certain
> control, therefore that control's validating event is never called, so
> my Error collecting sub will not return anything for this control.  I
> need to be able to loop through all controls on a form and call each
> control's validating event.  I need this code to be reusable for
> multiple forms.  Any suggestions.
>
> This does not work:
>
> Public Function CallEventOfCtrl( Controls as controlcollection) as
> string
> for each c as control in Controls
>     c.Validated
>     'or
>     call c.validated
> next
> End function
>

Warning... VB6 answers are all I have but... doesn't dotNet have a
ValidateControls method? Events aren't really something you should call
directly. Especially for controls that have no code in that specific event.
In VB6, ValidateControls raises the Validate event for any control that
currently has focus. I'm sure dotNet has something similar... well... ran
ValidateControls through the "one eyed wizard" and it spits out...

Call VB6.ValidateControls(Me)

....so it's a start.

--
Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..
Author
12 Apr 2006 10:27 PM
Bryan
..net has support for the ValidateControls method, but it is only used
for projects that are being upgraded from from VB6.   Each control in
the collection has a validated event, but control events don't seem to
be accessible from outside their parent form.
Author
12 Apr 2006 10:27 PM
Bryan
..net has support for the ValidateControls method, but it is only used
for projects that are being upgraded from from VB6.   Each control in
the collection has a validated event, but control events don't seem to
be accessible from outside their parent form.