PC Review


Reply
Thread Tools Rate Thread

control type

 
 
J L
Guest
Posts: n/a
 
      4th Apr 2005
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
 
Reply With Quote
 
 
 
 
Stephany Young
Guest
Posts: n/a
 
      4th Apr 2005
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.


"J L" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      4th Apr 2005
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


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      4th Apr 2005
"J L" <(E-Mail Removed)> 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/>
 
Reply With Quote
 
J L
Guest
Posts: n/a
 
      4th Apr 2005
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-(E-Mail Removed)> wrote:

>"J L" <(E-Mail Removed)> 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
>///


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      4th Apr 2005
"J L" <(E-Mail Removed)> 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/>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
REQ: looking for help/pointers on customising tool/control tips for Flexgrid please? (e..g. balloon type and fore/back colour control) sysarch Microsoft Access Form Coding 1 11th Jul 2009 09:36 AM
Error: The base class includes the field 'Left1', but its type (left) is not compatible with the type of control (ASP.left_ascx). error John Dalberg Microsoft ASP .NET 1 13th Feb 2007 02:25 PM
I need a basic grid type control - not a data bound bloated control John Edens Microsoft Dot NET Framework Forms 2 14th Jul 2005 06:26 AM
User Control codebehind type not compatible with ASP type? =?Utf-8?B?TSBL?= Microsoft ASP .NET 0 22nd Nov 2004 09:39 PM
The base class includes the field but its type is not compatible with the type of control. Daniel Melo Microsoft ASP .NET 0 8th Jan 2004 08:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:54 AM.