473,895 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Looking for general Validating and Validated events in VS2005

I'd like to call my ancestor Validation Function every time any control on a
Win Form generates a Validating or Validated event. I'm using VB.

I've extended Textbox, for instance, to have its events do this for me, but
my extended textbox doesn't get created by those wonderful form setup wizards.

So,
1) Is there a way I can pick up these events without having to code for each
control and without using custom extended controls, OR

2) Is there a way I can tell the Wizards to use my extended textboxes
instead of standard textboxes?
May 4 '06 #1
7 1762
"Bruce HS" <Br*****@discus sions.microsoft .com> wrote in message
news:44******** *************** ***********@mic rosoft.com...
I'd like to call my ancestor Validation Function every time any control on
a
Win Form generates a Validating or Validated event. I'm using VB.

I've extended Textbox, for instance, to have its events do this for me,
but
my extended textbox doesn't get created by those wonderful form setup
wizards.

So,
1) Is there a way I can pick up these events without having to code for
each
control and without using custom extended controls, OR
iterate over the controls collection, casting each element to textbox and
then wiring up the event handler

2) Is there a way I can tell the Wizards to use my extended textboxes
instead of standard textboxes?

Don't know about VB, in C# put at the top of your namespace
using TextBox = MyStuff.Extende dTextbox;

May 4 '06 #2
Not sure either works for me:
1) Iterating through controls will happen at run time. Are you saying that
I create event logic at runtime? I thought event logic had to be coded
before running.

2) When I use the wizard to build controls in the form, I don't think I'm in
a custom namespace. Would your Using command extend textboxes already
created by the wizard?

"Ben Voigt" wrote:
"Bruce HS" <Br*****@discus sions.microsoft .com> wrote in message
news:44******** *************** ***********@mic rosoft.com...
I'd like to call my ancestor Validation Function every time any control on
a
Win Form generates a Validating or Validated event. I'm using VB.

I've extended Textbox, for instance, to have its events do this for me,
but
my extended textbox doesn't get created by those wonderful form setup
wizards.

So,
1) Is there a way I can pick up these events without having to code for
each
control and without using custom extended controls, OR


iterate over the controls collection, casting each element to textbox and
then wiring up the event handler

2) Is there a way I can tell the Wizards to use my extended textboxes
instead of standard textboxes?


Don't know about VB, in C# put at the top of your namespace
using TextBox = MyStuff.Extende dTextbox;


May 4 '06 #3
"Bruce HS" <Br*****@discus sions.microsoft .com> wrote in message
news:CA******** *************** ***********@mic rosoft.com...
Not sure either works for me:
1) Iterating through controls will happen at run time. Are you saying
that
I create event logic at runtime? I thought event logic had to be coded
before running.

2) When I use the wizard to build controls in the form, I don't think I'm
in
a custom namespace. Would your Using command extend textboxes already
created by the wizard?
You are posting in the .NET newsgroup, so I'm assuming this is VB.NET, not
VB6.

The wizard doesn't create textboxes. The wizard adds code to an
InitializeCompo nent method in your form source file. Looking at the code it
creates, though, it uses fully-qualified class names, so a using statement
wouldn't have any effect.

"Event logic" as you call it, that you are adding with the wizard, has two
parts. One is the actual code to run, called an event handler, which is
actually just a normal method with a particular set of arguments (usually
object sender, EventArgs args) which the wizard stubs for you. It sounds as
if you want a single set of code shared among all textboxes, and to inspect
the sender parameter to find out which textbox, possibly to change
background color to red on validation failure, etc. The second part of
"event logic" is the wiring which connects the event handler with the event
belonging to a particular control. You've used the wizard, via double-click
or the events section of the property page, but it actually again adds code
into the InitializeCompo nent method, looking like (C#):
this.Load += new System.EventHan dler(this.Form_ Load);

This wiring you can do at runtime in a loop to connect an event handler to
all textboxes equally. Find one of the event hookup lines in your
InitializeCompo nent and generalize it (moving it to the Form constructor
right after the call to InitializeCompo nent).


"Ben Voigt" wrote:
"Bruce HS" <Br*****@discus sions.microsoft .com> wrote in message
news:44******** *************** ***********@mic rosoft.com...
> I'd like to call my ancestor Validation Function every time any control
> on
> a
> Win Form generates a Validating or Validated event. I'm using VB.
>
> I've extended Textbox, for instance, to have its events do this for me,
> but
> my extended textbox doesn't get created by those wonderful form setup
> wizards.
>
> So,
> 1) Is there a way I can pick up these events without having to code for
> each
> control and without using custom extended controls, OR


iterate over the controls collection, casting each element to textbox and
then wiring up the event handler
>
> 2) Is there a way I can tell the Wizards to use my extended textboxes
> instead of standard textboxes?
>


Don't know about VB, in C# put at the top of your namespace
using TextBox = MyStuff.Extende dTextbox;
>


May 4 '06 #4
Thanks! That led me to it. Here is the solution in VB:

Dim C As Control
For Each C In Me.Controls
If C.GetType.Name. ToLower = "textbox" Then
AddHandler C.Validating, AddressOf TextBox_Validat ing
End If
Next

"Ben Voigt" wrote:
"Bruce HS" <Br*****@discus sions.microsoft .com> wrote in message
news:CA******** *************** ***********@mic rosoft.com...
Not sure either works for me:
1) Iterating through controls will happen at run time. Are you saying
that
I create event logic at runtime? I thought event logic had to be coded
before running.

2) When I use the wizard to build controls in the form, I don't think I'm
in
a custom namespace. Would your Using command extend textboxes already
created by the wizard?


You are posting in the .NET newsgroup, so I'm assuming this is VB.NET, not
VB6.

The wizard doesn't create textboxes. The wizard adds code to an
InitializeCompo nent method in your form source file. Looking at the code it
creates, though, it uses fully-qualified class names, so a using statement
wouldn't have any effect.

"Event logic" as you call it, that you are adding with the wizard, has two
parts. One is the actual code to run, called an event handler, which is
actually just a normal method with a particular set of arguments (usually
object sender, EventArgs args) which the wizard stubs for you. It sounds as
if you want a single set of code shared among all textboxes, and to inspect
the sender parameter to find out which textbox, possibly to change
background color to red on validation failure, etc. The second part of
"event logic" is the wiring which connects the event handler with the event
belonging to a particular control. You've used the wizard, via double-click
or the events section of the property page, but it actually again adds code
into the InitializeCompo nent method, looking like (C#):
this.Load += new System.EventHan dler(this.Form_ Load);

This wiring you can do at runtime in a loop to connect an event handler to
all textboxes equally. Find one of the event hookup lines in your
InitializeCompo nent and generalize it (moving it to the Form constructor
right after the call to InitializeCompo nent).


"Ben Voigt" wrote:
"Bruce HS" <Br*****@discus sions.microsoft .com> wrote in message
news:44******** *************** ***********@mic rosoft.com...
> I'd like to call my ancestor Validation Function every time any control
> on
> a
> Win Form generates a Validating or Validated event. I'm using VB.
>
> I've extended Textbox, for instance, to have its events do this for me,
> but
> my extended textbox doesn't get created by those wonderful form setup
> wizards.
>
> So,
> 1) Is there a way I can pick up these events without having to code for
> each
> control and without using custom extended controls, OR

iterate over the controls collection, casting each element to textbox and
then wiring up the event handler

>
> 2) Is there a way I can tell the Wizards to use my extended textboxes
> instead of standard textboxes?
>

Don't know about VB, in C# put at the top of your namespace
using TextBox = MyStuff.Extende dTextbox;

>


May 5 '06 #5
Bruce,

I did not direct understand your question.

The trouble with what you have now is that you get only the controls direct
on the form.

Have a look at this sample on our website to change what you have a little
bit.

http://www.vb-tips.com/default.aspx?...6-56e3599238c1

While if you want to do it a little more sophisticated

\\\
If typeof C Is Textbox
///

I hope this helps,

Cor

"Bruce HS" <Br*****@discus sions.microsoft .com> schreef in bericht
news:F4******** *************** ***********@mic rosoft.com...
Thanks! That led me to it. Here is the solution in VB:

Dim C As Control
For Each C In Me.Controls
If C.GetType.Name. ToLower = "textbox" Then
AddHandler C.Validating, AddressOf TextBox_Validat ing
End If
Next

"Ben Voigt" wrote:
"Bruce HS" <Br*****@discus sions.microsoft .com> wrote in message
news:CA******** *************** ***********@mic rosoft.com...
> Not sure either works for me:
> 1) Iterating through controls will happen at run time. Are you saying
> that
> I create event logic at runtime? I thought event logic had to be coded
> before running.
>
> 2) When I use the wizard to build controls in the form, I don't think
> I'm
> in
> a custom namespace. Would your Using command extend textboxes already
> created by the wizard?


You are posting in the .NET newsgroup, so I'm assuming this is VB.NET,
not
VB6.

The wizard doesn't create textboxes. The wizard adds code to an
InitializeCompo nent method in your form source file. Looking at the code
it
creates, though, it uses fully-qualified class names, so a using
statement
wouldn't have any effect.

"Event logic" as you call it, that you are adding with the wizard, has
two
parts. One is the actual code to run, called an event handler, which is
actually just a normal method with a particular set of arguments (usually
object sender, EventArgs args) which the wizard stubs for you. It sounds
as
if you want a single set of code shared among all textboxes, and to
inspect
the sender parameter to find out which textbox, possibly to change
background color to red on validation failure, etc. The second part of
"event logic" is the wiring which connects the event handler with the
event
belonging to a particular control. You've used the wizard, via
double-click
or the events section of the property page, but it actually again adds
code
into the InitializeCompo nent method, looking like (C#):
this.Load += new System.EventHan dler(this.Form_ Load);

This wiring you can do at runtime in a loop to connect an event handler
to
all textboxes equally. Find one of the event hookup lines in your
InitializeCompo nent and generalize it (moving it to the Form constructor
right after the call to InitializeCompo nent).

>
> "Ben Voigt" wrote:
>
>> "Bruce HS" <Br*****@discus sions.microsoft .com> wrote in message
>> news:44******** *************** ***********@mic rosoft.com...
>> > I'd like to call my ancestor Validation Function every time any
>> > control
>> > on
>> > a
>> > Win Form generates a Validating or Validated event. I'm using VB.
>> >
>> > I've extended Textbox, for instance, to have its events do this for
>> > me,
>> > but
>> > my extended textbox doesn't get created by those wonderful form
>> > setup
>> > wizards.
>> >
>> > So,
>> > 1) Is there a way I can pick up these events without having to code
>> > for
>> > each
>> > control and without using custom extended controls, OR
>>
>> iterate over the controls collection, casting each element to textbox
>> and
>> then wiring up the event handler
>>
>> >
>> > 2) Is there a way I can tell the Wizards to use my extended
>> > textboxes
>> > instead of standard textboxes?
>> >
>>
>> Don't know about VB, in C# put at the top of your namespace
>> using TextBox = MyStuff.Extende dTextbox;
>>
>> >
>>
>>
>>


May 5 '06 #6
Thank you for your tip on seeing child controls.

Why is "If typeof C Is Textbox" Better than "If C.GetType.Name. ToLower =
"textbox"" ?

"Cor Ligthert [MVP]" wrote:
Bruce,

I did not direct understand your question.

The trouble with what you have now is that you get only the controls direct
on the form.

Have a look at this sample on our website to change what you have a little
bit.

http://www.vb-tips.com/default.aspx?...6-56e3599238c1

While if you want to do it a little more sophisticated

\\\
If typeof C Is Textbox
///

I hope this helps,

Cor

"Bruce HS" <Br*****@discus sions.microsoft .com> schreef in bericht
news:F4******** *************** ***********@mic rosoft.com...
Thanks! That led me to it. Here is the solution in VB:

Dim C As Control
For Each C In Me.Controls
If C.GetType.Name. ToLower = "textbox" Then
AddHandler C.Validating, AddressOf TextBox_Validat ing
End If
Next

"Ben Voigt" wrote:
"Bruce HS" <Br*****@discus sions.microsoft .com> wrote in message
news:CA******** *************** ***********@mic rosoft.com...
> Not sure either works for me:
> 1) Iterating through controls will happen at run time. Are you saying
> that
> I create event logic at runtime? I thought event logic had to be coded
> before running.
>
> 2) When I use the wizard to build controls in the form, I don't think
> I'm
> in
> a custom namespace. Would your Using command extend textboxes already
> created by the wizard?

You are posting in the .NET newsgroup, so I'm assuming this is VB.NET,
not
VB6.

The wizard doesn't create textboxes. The wizard adds code to an
InitializeCompo nent method in your form source file. Looking at the code
it
creates, though, it uses fully-qualified class names, so a using
statement
wouldn't have any effect.

"Event logic" as you call it, that you are adding with the wizard, has
two
parts. One is the actual code to run, called an event handler, which is
actually just a normal method with a particular set of arguments (usually
object sender, EventArgs args) which the wizard stubs for you. It sounds
as
if you want a single set of code shared among all textboxes, and to
inspect
the sender parameter to find out which textbox, possibly to change
background color to red on validation failure, etc. The second part of
"event logic" is the wiring which connects the event handler with the
event
belonging to a particular control. You've used the wizard, via
double-click
or the events section of the property page, but it actually again adds
code
into the InitializeCompo nent method, looking like (C#):
this.Load += new System.EventHan dler(this.Form_ Load);

This wiring you can do at runtime in a loop to connect an event handler
to
all textboxes equally. Find one of the event hookup lines in your
InitializeCompo nent and generalize it (moving it to the Form constructor
right after the call to InitializeCompo nent).
>
> "Ben Voigt" wrote:
>
>> "Bruce HS" <Br*****@discus sions.microsoft .com> wrote in message
>> news:44******** *************** ***********@mic rosoft.com...
>> > I'd like to call my ancestor Validation Function every time any
>> > control
>> > on
>> > a
>> > Win Form generates a Validating or Validated event. I'm using VB.
>> >
>> > I've extended Textbox, for instance, to have its events do this for
>> > me,
>> > but
>> > my extended textbox doesn't get created by those wonderful form
>> > setup
>> > wizards.
>> >
>> > So,
>> > 1) Is there a way I can pick up these events without having to code
>> > for
>> > each
>> > control and without using custom extended controls, OR
>>
>> iterate over the controls collection, casting each element to textbox
>> and
>> then wiring up the event handler
>>
>> >
>> > 2) Is there a way I can tell the Wizards to use my extended
>> > textboxes
>> > instead of standard textboxes?
>> >
>>
>> Don't know about VB, in C# put at the top of your namespace
>> using TextBox = MyStuff.Extende dTextbox;
>>
>> >
>>
>>
>>


May 5 '06 #7
Bruce,

Why is "If typeof C Is Textbox" Better than "If C.GetType.Name. ToLower =
"textbox"" ?

Without even looking to the underlying ILS (that is the generated code to
run) am I sure that the first one will be shorter than the second.

Cor
May 5 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1550
by: Omavlana | last post by:
Pleas advise me how to do validations in side datagrid before updating the details into database. I am using VB.NET and updating the datagrid using sqlcommandbuilder. I want to validate the data that user changhes inside the grid. How can I do this? Pls help...
2
1351
by: Osmosis | last post by:
I have a form with several controls, which all have their validating and validated events in my code. However, if these controls don't get focus, these events don't get called. When my OK button is pressed, I need all the controls to be validated. How can I get this done ? Do I have to call the events individually for each control, and if so, how do I do this ?
2
2136
by: Chris Dunaway | last post by:
I have a form with a textbox and numerous panels, buttons and other controls. I have handled the textbox Validating and Validated events. The textbox will hold a filename. In the validating event, I check that the string in the textbox is a file that exists or whether or not the string is blank and display a message box in either case. I also call e.Cancel so that the value will be corrected. However, certain buttons on the form...
21
9233
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on the cancel button, the textbox.validating is being called. I don't want it to be since they are exiting the screen the validation doesn't have to be done. How can I do that.
4
2485
by: easoftware | last post by:
I am using VS .Net 2003 and VB. I have an app with one parent and two Mdi child forms. I need to validate data in the Mdi form. The Form.Validating event works when I try to close a Mdi form, but not when I try to switch form one Mdi form to the other. I tried to add code to MdiForm1's Deactivate event: Private Sub MidForm1_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate Dim TempE As...
6
4761
by: Ryan | last post by:
I have a windows form that I want to force validation on controls (text boxes) when the user clicks a "Save" button. The only way I've found to do this is to cycle through every control and call it's .Select() method. This is clunky though because you can see a flash in each text box as it's being validated. Here's my code Private Sub Save() For each c as control in Me.Controls If c.CanSelect() then c.Select()
1
1545
by: mehdi | last post by:
Hi, Consider a dialog that contains some control. You know, the form is validated when every single control in the form is validated successfully. However, if one control tries to cancel the validation process, the other controls are still validating! (i.e., the validating event of other controls are still raised). Is there anyway to cancel the entire validation process (at once) when the first control is not validated successfully?
1
3807
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I've noticed that controls do not raise a Validating event if they are contained in a ToolStripDropDown via a ToolStripControlHost item. Please run the following sample and follow the instructions on the form to reproduce this issue: ------------------------------------ Public Class Form1 Inherits Windows.Forms.Form
2
2686
by: Peted | last post by:
Hi if i derive a reference to a control on a winform (ie Control activeControl = somecontrol on the form) how can i test if that control has a validating or validated event and more importantly how can i tell that those events have finished so that i can test for a new situation. My problem is i am modding some existing code, were the TAB key keypress is captured by a external c# module.
0
9990
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9835
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10473
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7177
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5863
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6068
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4689
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4285
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3294
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.