|
-
Apr 8th, 2004, 12:04 AM
#1
Thread Starter
New Member
How do you access group box controls that are in a collection
Hi, I'm a newb and this has been killing me. I have a collection of groupboxes. Each groupbox has two radio buttons. How do I access the radio buttons?
"cllGrpBoxTFQuestions(1).rdot.selected = False" doesn't seem to work.
Thanks for any help you can give
Steve
-
Apr 8th, 2004, 01:21 AM
#2
Junior Member
Can you please be a littlebit more specific?
What are you trying to do?
If you want to react on a click on one of the radio buttons, you have to use the radiobutton.CheckStateChanged event.
If you want to control the radiobuttons, you will have to use the CheckState event.
-
Apr 8th, 2004, 12:54 PM
#3
Thread Starter
New Member
Yeah, I guess I wasn't very specific. Basically, I'm writing sort of a questionaire or test. It reads the questions from a file. Each question will be placed in a groupbox as a label. The groupbox also contains another groupbox that houses the radio buttons.
Each question group box (containing questions and choices) is added to a collection. There are three questions per page so a next button loads the next three questions onto the form.
So, whenever I hit either the next or previous button, I'd like to store my answers to an array (for now). I just don't know how to refer to the radio buttons inorder to check their state.
Here is a sample of how each question is organized:
VB Code:
grpBoxTFQuestion = New GroupBox
With grpBoxTFQuestion
.Size = gbTFq.Size
End With
lbltfquest = New Label 'creates a new label
grpBoxTFQuestion.Controls.Add(lbltfquest) 'adds the question in the group box
With lbltfquest
.Size = lblTFQuestion.Size
.Text = p(1)
.Location = lblTFQuestion.Location
End With
grpboxRDOButtons = New GroupBox 'group box for true false selection
grpBoxTFQuestion.Controls.Add(grpboxRDOButtons)
With grpboxRDOButtons
.Size = gbTF.Size
.Location = gbTF.Location
End With
rdoT = New RadioButton
grpboxRDOButtons.Controls.Add(rdoT)
With rdoT
.Size = rdoTrue.Size
.Location = rdoTrue.Location
.Text = rdoTrue.Text
End With
rdoF = New RadioButton
grpboxRDOButtons.Controls.Add(rdoF)
With rdoF
.Size = rdoFalse.Size
.Location = rdoFalse.Location
.Text = rdoFalse.Text
End With
I'm sure it's a simple answer, but I'm an even bigger simpleton!!!
Last edited by stefanos33; Apr 8th, 2004 at 02:48 PM.
-
Apr 8th, 2004, 02:13 PM
#4
Frenzied Member
each radio button has it's own unique name. simply use that name.
opt1.checked = true or
if opt2.check = true then....
from what I can see in your code, you are creating those by code. (the hard way). you need to assign the "name" property also. then it's amatter of using that as above.
-
Apr 8th, 2004, 02:35 PM
#5
Thread Starter
New Member
Sorry for not formatting my code. I will go back and do that.
Actually, that block of code sits in a do while loop. Therefore, each radio button has the same name as far as I can tell. At each iteration of the loop (if another line exists in the text file), the group box with all its contents gets added to a collection.
I thought I could refer to each radio button like this:
VB Code:
if cllGrpBoxTFQuestions(1).grpboxRDOButtons.rdot.selected = False then
blah blah blah
esle
blah
end if
But that doesn't work.
would I be better off trying to slightly change each radio button slightly by appending a number to the name at each iteration? (i.e. rdoT1, rdoT2,...etc.)
I guess I'll try that when I get home. Right now I'm at work so I can't do anything.
Thanks again,
Steve
Last edited by stefanos33; Apr 8th, 2004 at 02:50 PM.
-
Apr 8th, 2004, 03:06 PM
#6
Frenzied Member
no, if your code is in the same class (the form) as the control, you won't need to fully qualify it. But, if you do, it will work. SO...you are putting in the wrong name it seems like.
the name actually is what you declared it as. I wasn't paying attention so that's good.
if you're radio button is named opt1, for example, and regardless of where it is on that form, you just need to use it's name:
opt1.checked (this is a boolean that will get/set the checkedState)
so, in your case:
VB Code:
if cllGrpBoxTFQuestions(1).grpboxRDOButtons.rdot.selected = False then
blah blah blah
esle
blah
end if
you need to rewrite it:
VB Code:
if rdot.checked then 'if it IS checked
hum didly ho 'The Do this
else 'otherwise
hooahh. Do THIS
end if
-
Apr 9th, 2004, 09:08 AM
#7
Thread Starter
New Member
Thanks Andy it worked,
Based on what you told me, I made an array of radio butons so they each could be uniquely identified even though they had the same name.
steve
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
|