Reputation: 53
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.
Upvotes: 0
Views: 736
Reputation: 8004
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!
Upvotes: 1
Reputation: 130
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?
Upvotes: 0