TabPage Collection of Controls and GetType Then Control Properties

TabPage Collection of Controls and GetType Then Control Properties

Post by Brad Cundif » Fri, 14 Dec 2001 23:30:02



I am attempting to iterate through a collection of controls on a
TabPage.  As I iterate through them, I want to determine the type of
the control and then assign some property, i.e. radiobutton.checked =
False, TextBox.Text = "", etc.
I can get through both collections fine but once I determine the type,
do I have to cast the control to a radiobutton type to get it to
recognize the radio button properties?

fyi: TabEvents is a TabControl

Here's the code I have so far:

Dim MyTab as System.Windows.Forms.TabPage
Dim c as Control

For Each MyTab in TabEvents.TabPages
     For Each c in MyTab.Controls
        If c.GetType Is GetType(System.Windows.Forms.RadioButton) Then
           ????? How do I get my control to recognize the checked
                      property for a RadioButton  ????
        Then
     Next
Next

 
 
 

TabPage Collection of Controls and GetType Then Control Properties

Post by Brad Cundif » Fri, 14 Dec 2001 23:30:50


I am attempting to iterate through a collection of controls on a
TabPage.  As I iterate through them, I want to determine the type of
the control and then assign some property, i.e. radiobutton.checked =
False, TextBox.Text = "", etc.
I can get through both collections fine but once I determine the type,
do I have to cast the control to a radiobutton type to get it to
recognize the radio button properties?

fyi: TabEvents is a TabControl

Here's the code I have so far:

Dim MyTab as System.Windows.Forms.TabPage
Dim c as Control

For Each MyTab in TabEvents.TabPages
     For Each c in MyTab.Controls
        If c.GetType Is GetType(System.Windows.Forms.RadioButton) Then
           ????? How do I get my control to recognize the checked
                      property for a RadioButton  ????
        Then
     Next
Next

 
 
 

TabPage Collection of Controls and GetType Then Control Properties

Post by MVP » Fri, 14 Dec 2001 23:56:19


Quote:> Here's the code I have so far:

> Dim MyTab as System.Windows.Forms.TabPage
> Dim c as Control

> For Each MyTab in TabEvents.TabPages
>      For Each c in MyTab.Controls
>         If c.GetType Is GetType(System.Windows.Forms.RadioButton) Then
>            ????? How do I get my control to recognize the checked
>                       property for a RadioButton  ????
>         Then
>      Next
> Next

You have to cast c to the correct type. . .  e.g. CType(c, RadioButton)

--
Jacob Grass
Microsoft .NET MVP