Selecting all check boxes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • programmerboy
    New Member
    • Jul 2007
    • 84

    Selecting all check boxes

    I know how to do this in web applications, but I am having a hard time doing this in a windows application. Here is my code below.

    Code:
    For Each ctrl In Me.Controls
                If TypeOf (ctrl) Is CheckBox Then
                    ctrl.
                End If
    Next
    What I am missing here?
  • EinToR
    New Member
    • May 2008
    • 20

    #2
    Did you try this? :

    Code:
    For Each ctrl In Me.Controls
                If TypeOf (ctrl) Is CheckBox Then
                    ctrl.Checked = True
                End If
    Next
    Last edited by EinToR; May 16 '08, 03:52 PM. Reason: Messed up [CODE][/CODE] tags...

    Comment

    • programmerboy
      New Member
      • Jul 2007
      • 84

      #3
      Originally posted by EinToR
      Did you try this? :

      Code:
      For Each ctrl In Me.Controls
                  If TypeOf (ctrl) Is CheckBox Then
                      ctrl.Checked = True
                  End If
      Next
      Yeh it doesnt work. I have tried it before. It says that check is not a member of System.Windows. Form.Control.

      Comment

      • EinToR
        New Member
        • May 2008
        • 20

        #4
        Try casting ctrl to type CheckBox. It might look something along the lines of this:

        Code:
        For Each ctrl In Me.Controls
            If TypeOf (ctrl) Is CheckBox Then
                CType(ctrl, CheckBox).Checked = True
            End If
        Next
        I'm really not sure how to cast in VB...

        Comment

        • programmerboy
          New Member
          • Jul 2007
          • 84

          #5
          Originally posted by EinToR
          Try casting ctrl to type CheckBox. It might look something along the lines of this:

          Code:
          For Each ctrl In Me.Controls
              If TypeOf (ctrl) Is CheckBox Then
                  CType(ctrl, CheckBox).Checked = True
              End If
          Next
          I'm really not sure how to cast in VB...
          You did cast it right. Thanks man, your thingee worked.

          Comment

          • EinToR
            New Member
            • May 2008
            • 20

            #6
            Awesome! Glad I could help.

            Comment

            Working...