Results 1 to 7 of 7

Thread: How do you access group box controls that are in a collection

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    4

    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

  2. #2
    Junior Member
    Join Date
    Mar 2004
    Location
    Netherlands
    Posts
    27
    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.
    *(^.^); c(_)

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    4
    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:
    1. grpBoxTFQuestion = New GroupBox
    2.  
    3.         With grpBoxTFQuestion
    4.             .Size = gbTFq.Size          
    5.         End With
    6.  
    7.         lbltfquest = New Label 'creates a new label
    8.         grpBoxTFQuestion.Controls.Add(lbltfquest) 'adds the question in the group box
    9.         With lbltfquest
    10.             .Size = lblTFQuestion.Size
    11.             .Text = p(1)
    12.             .Location = lblTFQuestion.Location
    13.         End With
    14.  
    15.         grpboxRDOButtons = New GroupBox 'group box for true false selection
    16.         grpBoxTFQuestion.Controls.Add(grpboxRDOButtons)
    17.         With grpboxRDOButtons
    18.             .Size = gbTF.Size
    19.             .Location = gbTF.Location
    20.         End With
    21.  
    22.         rdoT = New RadioButton
    23.         grpboxRDOButtons.Controls.Add(rdoT)
    24.         With rdoT
    25.             .Size = rdoTrue.Size
    26.             .Location = rdoTrue.Location
    27.             .Text = rdoTrue.Text
    28.         End With
    29.  
    30.  
    31.         rdoF = New RadioButton
    32.         grpboxRDOButtons.Controls.Add(rdoF)
    33.         With rdoF
    34.             .Size = rdoFalse.Size
    35.             .Location = rdoFalse.Location
    36.             .Text = rdoFalse.Text
    37.         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.

  4. #4
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    4
    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:
    1. if cllGrpBoxTFQuestions(1).grpboxRDOButtons.rdot.selected = False  then
    2.       blah blah blah
    3. esle
    4.       blah
    5. 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.

  6. #6
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    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:
    1. if cllGrpBoxTFQuestions(1).grpboxRDOButtons.rdot.selected = False  then
    2.       blah blah blah
    3. esle
    4.       blah
    5. end if

    you need to rewrite it:
    VB Code:
    1. if rdot.checked then 'if it IS checked
    2. hum didly ho            'The Do this
    3. else                          'otherwise
    4. hooahh.                   Do THIS
    5. end if

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    4
    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
  •  



Click Here to Expand Forum to Full Width