"Ronin" <Ro***@discussions.microsoft.com> schrieb
group,
please help with the following codes below.
why would this not work... would it require casting/reflecting? if
so, does anyone show me the right codes?
Dim chk As System.Windows.Forms.CheckBox
If Not MsgBox("Are you sure you wish to clear?",
MsgBoxStyle.YesNo + MsgBoxStyle.Exclamation, "Clearing") =
MsgBoxResult.Yes Then Exit Sub
For Each ctl In Me.Controls
If TypeName(ctl) = "GroupBox" Then
For Each chk In ctl.Controls
chk.Checked = False
Next
End If
Next
I tried it and it works here.
"Not work" means what? Compile error? Exception? Maybe either the groupbox
is not directly placed on the Form, or not all controls in the Groupbox are
checkboxes. If the latter is the case, use
For Each ctl2 as Control In ctl.Controls
if typeof ctl2 is Checkbox then
dim chk as checkbox=directcast(ctl2, checkbox)
chk.Checked = False
end if
Next
BTW, I would use
If typeof ctl is GroupBox
instead, because the compiler would discover a misspelled type name. But
this is not the reason for the problem.
Armin