Solved

For Each control in TabPage

Posted on 2004-08-04
10
318 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 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

18 Experts available now in Live!

Get 1:1 Help Now