Home All Groups Group Topic Archive Search About

Select All CheckBoxes

Author
2 Dec 2006 6:41 PM
Newbie Coder
Hello All

How do I select all checkboxes on a TabControl in code?

I have tried this, but the CHECKED property, doesn't work because its not
part of the Control class

        Dim c As Control
        For Each c In Me.Controls
            If TypeOf c Is CheckBox Then
                c.Checked = True
            End If
        Next

I have tried substituting the TabControl.Controls but still nothing

I tried using a New statement after the If TypeOf line, but still no joy.

Any Ideas what I am doing wrong?

TIA

Author
2 Dec 2006 6:39 PM
Oenone
Newbie Coder wrote:
> I have tried this, but the CHECKED property, doesn't work because its
> not part of the Control class
[...]

Try this:

\\\
    Dim c As Control
    For Each c In Me.Controls
        If TypeOf c Is CheckBox Then
            DirectCast(c, CheckBox).Checked = True
        End If
    Next
///

Because you know that c is of type CheckBox, you can safely cast it to that
type. Then it will recognise that Checked is a valid property and set it
without any problems.

HTH,

--

(O)enone
Author
2 Dec 2006 6:53 PM
Newbie Coder
Sorry, but your code doesn't check any checkboxes in the project


Show quoteHide quote
"Oenone" <oen***@nowhere.com> wrote in message
news:hLjch.1633$r95.42@newsfe6-win.ntli.net...
> Newbie Coder wrote:
> > I have tried this, but the CHECKED property, doesn't work because its
> > not part of the Control class
> [...]
>
> Try this:
>
> \\\
>     Dim c As Control
>     For Each c In Me.Controls
>         If TypeOf c Is CheckBox Then
>             DirectCast(c, CheckBox).Checked = True
>         End If
>     Next
> ///
>
> Because you know that c is of type CheckBox, you can safely cast it to
that
> type. Then it will recognise that Checked is a valid property and set it
> without any problems.
>
> HTH,
>
> --
>
> (O)enone
>
>
Author
2 Dec 2006 8:35 PM
Oenone
Newbie Coder wrote:
> Sorry, but your code doesn't check any checkboxes in the project

Well then, over to you to work out why not. :)

Does the .Checked=True line get called at all? If not, why not? If it does,
which control is contained in c? What is the value of c.Checked before and
after the property is set?

--

(O)enone