Clear all checkboxes at form load

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mcmahon
    New Member
    • Feb 2009
    • 9

    #1

    Clear all checkboxes at form load

    Hi,

    I have a pile of checkboxes on one particular form and would like to clear them all at the form load rather that saying chk1.Checked = False for all of them.

    Here is the code I was trying to use but 'checked' is not a member of Systems.Windows .Forms.Controls .
    [Code=VBNET]
    Dim ctl As Control
    For Each ctl In Me.Controls
    If TypeOf ctl Is CheckBox Then
    ctl.checked = False
    End If
    Next ctl
    [/CODE]
    How can I fix this??
    Thanks.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Well how did they get checked in the first place?
    When a form loads it reads the values from what you set in the designer.
    So at design time make sure they are all false?


    Otherwise your sample code is almost right, you would just need to check inside container controls (GroupBox for example) and check their child controls to see if they are checkboxes.
    As for your error, your are not casting the control as a CheckBox before trying to use the Checked proeprty

    Comment

    • mcmahon
      New Member
      • Feb 2009
      • 9

      #3
      Thanks.
      Sorted now

      Comment

      Working...