Call control's event from a collection

B

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
 
K

Ken Halter

Bryan said:
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.
 
B

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.
 
B

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.
 

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