|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
For Each... statementplease 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 Please help. Thanks in advance. Ronin >why would this not work... The enumerator returns all controls regardless of the type of youriteration variable (chk As CheckBox in this case). You have to do something like For Each chk As Control In ctl.Controls If TypeOf chk Is CheckBox Then CType(chk, CheckBox).Checked =False Next Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup.
Show quote
Hide quote
"Ronin" <Ro***@discussions.microsoft.com> schrieb I tried it and it works here.> 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 "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 "Ronin" <Ro***@discussions.microsoft.com> wrote in message Something like this :news:23AEF258-0C81-4713-837E-6825A84B93BF@microsoft.com... > why would this not work... would it require casting/reflecting? if so, > does > anyone show me the right codes? Option Strict On Imports System.Windows.Forms .. . . If MsgBox("Are you sure you wish to clear?" _ , MsgBoxStyle.YesNo Or MsgBoxStyle.Question _ , "Clearing") = MsgBoxResult.Yes _ Then For Each possibleGB As Control In Me.Controls If TypeOf( possibleGB ) Is GroupBox Then For Each possibleCB As Control In ctl.Controls If TypeOf( possibleCB ) Is CheckBox Then DirectCast( possibleCB, Checkbox).Checked = False End If Next End If Next End If HTH, Phill W.
Using AxWebBrowser in VB 2005
Domain search like setting file permissions Proble about "send" Text on Image Resolution Reading Stream After RedirectStandardOutput=True Blocks Confusion on Protected Overrides checking for EOF time expressions Loop through columns of all datarows in a dataset my form cannot from from network |
|||||||||||||||||||||||