Link to home
Start Free TrialLog in
Avatar of Grunge
GrungeFlag for United Kingdom of Great Britain and Northern Ireland

asked on

For Each control in TabPage

hi all!

        Dim n As CheckBox
        For Each n In fMain.tabReports.Controls
            n.Checked = False
        Next

        Dim n As CheckBox
        For Each n In fMain.tabReports.ControlCollection
            n.Checked = False
        Next

neither of these work... ideas?
Avatar of Fahad Mukhtar
Fahad Mukhtar
Flag of Pakistan image

Dim c As CheckBox
        For Each c In fMain.tabReports.TabPages(1).Controls
            c.Checked = False
        Next
Avatar of Grunge

ASKER

that returns an "invalid cast"

.............i should mention that tabReports is a tabPage (one of serveral) on a tab control (tabAll)
Avatar of Grunge

ASKER

so i tried

        For Each n In fMain.tabAll.TabPages(1).Controls()
            n.Checked = False
        Next

no joy
Avatar of jrandallsexton
jrandallsexton

           Dim chk As New CheckBox
            Dim ctl As Control
            For Each ctl In TabPage1.Controls
                If ctl.GetType.ToString = chk.GetType.ToString Then
                    CType(ctl, CheckBox).Checked = True
                End If
            Next
That doesn't work because the Controls collection most likely has more than just checkboxes.  You need to test for that...


    For Each ctl As Control In fMain.tabReports.TabPages(1).Controls()
          Try
               Dim chk As CheckBox = CType(ctl, CheckBox)
               chk.Checked = False        ' If you make it this far, the control is a Checkbox
          Catch
               'Ignore invalid cast exception
          End try
    Next
Hi,

I tried something similar, although i omitted the tab page container and just called the tabpage direct.

 Dim myChk As CheckBox

For Each myChk In Me.TabPage1.Controls
      myCont.Checked = True        'used true for visual confirmation
Next

Any Joy?

BS
SOLUTION
Avatar of jrandallsexton
jrandallsexton

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Grunge

ASKER

wow this topic suddenly took off!....

give me a tad to check the offerings then i will grade.

Regards

Grunge
Avatar of Grunge

ASKER

Thx all for your comments...