Solved

For Each control in TabPage

Posted on 2004-08-04
10
319 Views
Last Modified: 2010-04-23
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
Comment
Question by:Grunge
10 Comments
 
LVL 19

Expert Comment

by:Desp
ID: 11715352
Dim c As CheckBox
        For Each c In fMain.tabReports.TabPages(1).Controls
            c.Checked = False
        Next
0
 
LVL 1

Author Comment

by:Grunge
ID: 11715889
that returns an "invalid cast"

.............i should mention that tabReports is a tabPage (one of serveral) on a tab control (tabAll)
0
 
LVL 1

Author Comment

by:Grunge
ID: 11715903
so i tried

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

no joy
0
 
LVL 4

Expert Comment

by:jrandallsexton
ID: 11716071
           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
 
LVL 14

Expert Comment

by:ptakja
ID: 11716095
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Expert Comment

by:Babycorn-Starfish
ID: 11716103
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
 
LVL 4

Assisted Solution

by:jrandallsexton
jrandallsexton earned 100 total points
ID: 11716126
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
 
LVL 2

Accepted Solution

by:
djdidge earned 105 total points
ID: 11716168
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
 
LVL 1

Author Comment

by:Grunge
ID: 11716187
wow this topic suddenly took off!....

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

Regards

Grunge
0
 
LVL 1

Author Comment

by:Grunge
ID: 11716201
Thx all for your comments...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now