简体   繁体   中英

Unable to change checkstate of Checkboxes within panel control

Have a problem that is really bugging me. I have 8 checkboxes inside a panel control. the panel is in the automation.vb[design] file. Within Automation.vb, i do a simple loop to go through the controls and check which box is checked, and that works fine as it should:

            For Each chk As CheckBox In pnlSelectedDays.Controls
                If chk.Checked Then
                   'do things
                End If
            Next

However, when I need to check in another file, I have the same construction, but the controls never have a checkedstate, even if they are checked. It will be fine in the first file, but wrong in the second:

    For Each day As CheckBox In Automation.pnlSelectedDays.Controls
        If day.Checked Then
            'do some more things
        End If
    Next

Is it because I am calling from a different file? I'm a little new to winforms, usually do c++, so not sure if the structure is OK. If not, do I just make a shared public function in the automation.vb file so other files can call it?

EDIT: First example is called when a save button is hit on the automation form.
Second example is called from the OnClose event of the automation form.

Here's a bit of code I done up for you, give it a shot...

Public Sub ClearFields()

    For Each ctrl As Control In Animation.GroupBox1.Controls
        If TypeOf ctrl Is Checkbox Then
          CType(ctrl, Checkbox).Checked = False
        End If
    Next ctrl

End Sub

This will give you something to put a foot on, this is a sub you can call where you need it to be...

Thanks!

If I'm hearing you correctly (I'm on a conf call too) then it sounds like a timing issue. At form_load, values of the checkboxes are that which are assigned at design-time. How are you instantiating, loading, displaying the second form?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM