Home All Groups Group Topic Archive Search About
Author
4 Apr 2005 3:20 AM
J L
I am trying to step through the controls on a form and take some
action when I find a specific type. I dont know how to express this in
an If or Select clause.

I tried:

Dim Ctrl As Control
For Each Ctrl In Me.Controls
   If Ctrl.GetType = System.Windows.Forms.TextBox Then
      <take some action>
   End If
Next

and

Select Case Ctrl.GetType
   Case System.Windows.Forms.TextBox
      <take some action>
End Select

In both cases it says the System.Windows.Forms.TextBox type can not be
used in an expression. So how am I to do this compare?

TIA,
John

Author
4 Apr 2005 4:01 AM
Stephany Young
If Ctrl.GetType = System.Windows.Forms.TextBox.GetType Then

or

Case System.Windows.Forms.TextBox.GetType

Note: Your loop will not handle controls that are on 'container' controls
like GooupBox and Panel. To handle these you will need to use recursion.


Show quoteHide quote
"J L" <j***@marymonte.com> wrote in message
news:ubc151ti86dlv589c8535aejkj4m4gr5p6@4ax.com...
>I am trying to step through the controls on a form and take some
> action when I find a specific type. I dont know how to express this in
> an If or Select clause.
>
> I tried:
>
> Dim Ctrl As Control
> For Each Ctrl In Me.Controls
>   If Ctrl.GetType = System.Windows.Forms.TextBox Then
>      <take some action>
>   End If
> Next
>
> and
>
> Select Case Ctrl.GetType
>   Case System.Windows.Forms.TextBox
>      <take some action>
> End Select
>
> In both cases it says the System.Windows.Forms.TextBox type can not be
> used in an expression. So how am I to do this compare?
>
> TIA,
> John
Author
4 Apr 2005 6:53 AM
Cor Ligthert
JL,

To check the type of an  objects is the TypeOf and the  IS operator in VBNet
\\\
If TypeOf Ctr IS Textbox
///
I hope this helps,

Cor
Author
4 Apr 2005 11:24 AM
Herfried K. Wagner [MVP]
"J L" <j***@marymonte.com> schrieb:
>I am trying to step through the controls on a form and take some
> action when I find a specific type. I dont know how to express this in
> an If or Select clause.

\\\
If TypeOf Ctrl Is TextBox Then...
///

- or -

\\\
If Ctrl.GetType Is GetType(TextBox) Then...
///

'Select Case':

\\\
Select Case True
    Case TypeOf Ctrl Is TextBox
        ...
    Case TypeOf Ctrl Is Button
        ...
    ...
End Select
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
4 Apr 2005 1:27 PM
J L
Thank you Stephany, Cor and Herfried! That was what I was looking for.
And I am aware of needing recursion for containers but in my case that
is not necessary. Again I am grateful to all the Gurus on this NG and
especiallly you 3. I lurk and learn. So your work not only helps those
whose answer you provide but a lot of us who are watching you as
mentors.

Thanks,
John

On Mon, 4 Apr 2005 13:24:54 +0200, "Herfried K. Wagner [MVP]"
<hirf-spam-me-here@gmx.at> wrote:

Show quoteHide quote
>"J L" <j***@marymonte.com> schrieb:
>>I am trying to step through the controls on a form and take some
>> action when I find a specific type. I dont know how to express this in
>> an If or Select clause.
>
>\\\
>If TypeOf Ctrl Is TextBox Then...
>///
>
>- or -
>
>\\\
>If Ctrl.GetType Is GetType(TextBox) Then...
>///
>
>'Select Case':
>
>\\\
>Select Case True
>    Case TypeOf Ctrl Is TextBox
>        ...
>    Case TypeOf Ctrl Is Button
>        ...
>    ...
>End Select
>///
Author
4 Apr 2005 8:03 PM
Herfried K. Wagner [MVP]
"J L" <j***@marymonte.com> schrieb:
> Thank you Stephany, Cor and Herfried! That was what I was looking for.
> And I am aware of needing recursion for containers but in my case that
> is not necessary. Again I am grateful to all the Gurus on this NG and
> especiallly you 3. I lurk and learn. So your work not only helps those
> whose answer you provide but a lot of us who are watching you as
> mentors.

Thank you :-).

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>