• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 330
  • Last Modified:

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?
0
Grunge
Asked:
Grunge
2 Solutions
 
Fahad MukhtarDistinguished EngineerCommented:
Dim c As CheckBox
        For Each c In fMain.tabReports.TabPages(1).Controls
            c.Checked = False
        Next
0
 
GrungeAuthor Commented:
that returns an "invalid cast"

.............i should mention that tabReports is a tabPage (one of serveral) on a tab control (tabAll)
0
 
GrungeAuthor Commented:
so i tried

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

no joy
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
jrandallsextonCommented:
           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
0
 
ptakjaCommented:
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
0
 
Babycorn-StarfishCommented:
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
0
 
jrandallsextonCommented:
Maybe I should add comments tot my post:

            Dim chk As New CheckBox 'used for type conparison
            Dim ctl As Control 'create a control object to use as the enumerator
            For Each ctl In TabPage1.Controls 'enumerate the collection
                If ctl.GetType.ToString = chk.GetType.ToString Then 'determine if the current control is in fact a checkbox
                    CType(ctl, CheckBox).Checked = True 'if we're here, then the current control is a checkbox.  You must convert the object to a checkbox before setting the checked property
                End If
            Next
0
 
djdidgeCommented:
try this... very similar to some of the others but perhaps a tad more readable

        Dim Ctrl As Control
        Dim childCtrl As Control

        For Each Ctrl In fMain.tabAll.TabPages(1).Controls()
            For Each childCtrl In Ctrl.Controls
                If TypeOf childCtrl Is CheckBox Then CType(childCtrl, CheckBox).Checked = False
            Next childCtrl
        Next Ctrl
0
 
GrungeAuthor Commented:
wow this topic suddenly took off!....

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

Regards

Grunge
0
 
GrungeAuthor Commented:
Thx all for your comments...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now