Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,077 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,756 people online right now. Registration is fast and FREE... Join Now!




Radio buttons in a group box

 
Reply to this topicStart new topic

Radio buttons in a group box, Check to see if enabled on a form load

mikjall77
5 Mar, 2008 - 04:46 AM
Post #1

New D.I.C Head
*

Joined: 18 Apr, 2007
Posts: 46



Thanked: 1 times
My Contributions
I'm using VB2005 and have a group box that contains 2 to 4 radio buttons. When the user clicks the next button, the form will display the next set of 2-4 buttons in the group box. The program will also check to see if an actual button has been selected with the CheckChange Event. This all works except on the initial form load. If I press the next button without selecting a radio button in the first group, it still moves on to the next group. I've used the grpGroupBox.Tag = -1 and If/Then statements (which work on the subsequent groups) in various places and still can't get it to work. Any help is greatly appreciated!!
CODE
Private Sub frmTesting_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dsQuiz = oQuiz.GetData()
        lblTestName.Text = sTestName
           'hook up control array
        rdoAns(1) = rdoAns1
        rdoAns(2) = rdoAns2
        rdoAns(3) = rdoAns3
        rdoAns(4) = rdoAns4
           'retrieve the info from the view
        dtQuizQuesAns = oQuiz.GetQuizQuesAns(iTestID)
        dtQuizQuesAns.TableName = "qryQzQstnAnsr" 'the tablename prop must not be "" to hook to a view
           'show the first question
        vwQ.Table = dtQuizQuesAns
        grpChoices.Tag = -1
        Call ShowAnswers(iCurrentQues)
    End Sub

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        If grpChoices.Tag = -1 Then
            'haven't answered question
            MessageBox.Show("Please answer the question before you continue.")
        Else
            iCurrentQues += 1
            If Not ShowAnswers(iCurrentQues) Then
                iCurrentQues -= 1  'went to far - back up one
                ShowAnswers(iCurrentQues)
            End If
            grpChoices.Tag = -1
        End If
        rdoAns(1).Focus()
    End Sub

User is offlineProfile CardPM
+Quote Post

Footsie
RE: Radio Buttons In A Group Box
5 Mar, 2008 - 11:22 PM
Post #2

D.I.C Regular
Group Icon

Joined: 20 Sep, 2007
Posts: 308



Thanked: 4 times
Dream Kudos: 50
My Contributions
I don't have much experience in VB (I work in C#) but what I would do is in the initial form load make your 'Next' button invisible. btnNext.Visible = false
Then when someone clicks the radio button to make a selection set the 'Next' button to visible. btnNext.Visible = true
In this way the user can only click the 'Next' button if they have already selected a radio button first.

I hope that helps. pirate.gif
User is offlineProfile CardPM
+Quote Post

mikjall77
RE: Radio Buttons In A Group Box
6 Mar, 2008 - 12:13 AM
Post #3

New D.I.C Head
*

Joined: 18 Apr, 2007
Posts: 46



Thanked: 1 times
My Contributions
Footsie,

Thanks for the great idea! Within my various radio button groups, there are times when I need only 2 of the 4 buttons and enable/disable them at that time. I should've thought of that for the initial group and done it with the next button like you said.

Thanks again for the great idea!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 11:15PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month