|
-
Jun 1st, 2006, 08:26 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] [02/03] Using the Controls Collection of a groupbox?
Hi all, I am trying to uncheck the currently checked radiobutton in a groupbox with 6 radiobuttons. I have this:
VB Code:
Dim RB As RadioButton
For Each RB In GroupBox4.Controls
RB.Checked = False
Next
I get "Specified cast is not valid" in line "For Each RB In GroupBox4.Controls". What am I doing wrong, the editor isn't showing any errors.
-
Jun 1st, 2006, 08:34 PM
#2
Re: [02/03] Using the Controls Collection of a groupbox?
You can't cast every control as a RadioButton if not every control IS a RadioButton. You need to check the type and only if it is a RadioButton can you then cast it as such and set its Checked property:
VB Code:
For Each ctl As Control In GroupBox4.Controls
If TypeOf ctl Is RadioButton Then
DirectCast(ctl, RadioButton).Checked = False
End If
Next ctl
-
Jun 1st, 2006, 08:38 PM
#3
Re: [02/03] Using the Controls Collection of a groupbox?
 Originally Posted by jmcilhinney
if not every control IS a RadioButton.
haha John.. you must be coding too much.. you are starting to write your sentences in VB syntax
-
Jun 1st, 2006, 08:43 PM
#4
Re: [02/03] Using the Controls Collection of a groupbox?
Me.HasLife = False
-
Jun 1st, 2006, 08:46 PM
#5
Thread Starter
Frenzied Member
Re: [02/03] Using the Controls Collection of a groupbox?
Ahh, I thought I can filter the collection further by providing what controls I am interested in. Thanks again, jmcilhinney (You must spread some Reputation around before giving it to jmcilhinney again )
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|