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? 7 1670
"Bruce HS" <Br*****@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.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.ExtendedTextbox;
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*****@discussions.microsoft.com> wrote in message news:44**********************************@microsof t.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.ExtendedTextbox;
"Bruce HS" <Br*****@discussions.microsoft.com> wrote in message
news:CA**********************************@microsof t.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
InitializeComponent 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 InitializeComponent method, looking like (C#):
this.Load += new System.EventHandler(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
InitializeComponent and generalize it (moving it to the Form constructor
right after the call to InitializeComponent). "Ben Voigt" wrote:
"Bruce HS" <Br*****@discussions.microsoft.com> wrote in message news:44**********************************@microsof t.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.ExtendedTextbox;
>
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_Validating
End If
Next
"Ben Voigt" wrote: "Bruce HS" <Br*****@discussions.microsoft.com> wrote in message news:CA**********************************@microsof t.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 InitializeComponent 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 InitializeComponent method, looking like (C#): this.Load += new System.EventHandler(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 InitializeComponent and generalize it (moving it to the Form constructor right after the call to InitializeComponent).
"Ben Voigt" wrote:
"Bruce HS" <Br*****@discussions.microsoft.com> wrote in message news:44**********************************@microsof t.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.ExtendedTextbox;
>
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*****@discussions.microsoft.com> schreef in bericht
news:F4**********************************@microsof t.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_Validating End If Next
"Ben Voigt" wrote:
"Bruce HS" <Br*****@discussions.microsoft.com> wrote in message news:CA**********************************@microsof t.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 InitializeComponent 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 InitializeComponent method, looking like (C#): this.Load += new System.EventHandler(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 InitializeComponent and generalize it (moving it to the Form constructor right after the call to InitializeComponent).
> > "Ben Voigt" wrote: > >> "Bruce HS" <Br*****@discussions.microsoft.com> wrote in message >> news:44**********************************@microsof t.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.ExtendedTextbox; >> >> > >> >> >>
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*****@discussions.microsoft.com> schreef in bericht news:F4**********************************@microsof t.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_Validating End If Next
"Ben Voigt" wrote:
"Bruce HS" <Br*****@discussions.microsoft.com> wrote in message news:CA**********************************@microsof t.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 InitializeComponent 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 InitializeComponent method, looking like (C#): this.Load += new System.EventHandler(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 InitializeComponent and generalize it (moving it to the Form constructor right after the call to InitializeComponent).
> > "Ben Voigt" wrote: > >> "Bruce HS" <Br*****@discussions.microsoft.com> wrote in message >> news:44**********************************@microsof t.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.ExtendedTextbox; >> >> > >> >> >>
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |