Results 1 to 3 of 3

Thread: [RESOLVED] group box and radio buttons

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2009
    Location
    Australia
    Posts
    130

    Resolved [RESOLVED] group box and radio buttons

    Hi folks.

    I have put some radio buttons into a group box. When I run the program and select a button, a message box pops up with a message about the current button, and then another box pops up with a message about the newly selected button. I understand that this is because CheckedChanged happens twice(for the current button and for the newly selected button).

    1. What can I do so that only the change for the newly selected button is recognised? I don't care about the CheckedChanged state for the currently selected button.

    2. Besides being a visual container for the radio buttons, does the group box server any other purpose, and should code for the group box be included in my code?

    Thanks in advance.

    Code:
    Public Class Form1
        Dim frequency As String
        
        Private Sub rdoYearly_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rdoYearly.CheckedChanged
            MsgBox("Yearly")
        End Sub
    
        Private Sub rdoWeekly_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rdoWeekly.CheckedChanged
            MsgBox("Weekly")
        End Sub
    
        Private Sub rdoMonthly_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rdoMonthly.CheckedChanged
            MsgBox("Monthly")
        End Sub
    
        Private Sub rdoDaily_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rdoDaily.CheckedChanged
            MsgBox("Daily")
        End Sub
    End Class
    Attached Images Attached Images  

  2. #2
    Fanatic Member
    Join Date
    Dec 2007
    Location
    West Yorkshire, UK
    Posts
    791

    Re: group box and radio buttons

    Code:
    If rdoYearly.Checked = True Then
       MsgBox "blah blah"
    End if

  3. #3
    Frenzied Member IanRyder's Avatar
    Join Date
    Jan 2013
    Location
    Healing, UK
    Posts
    1,232

    Re: group box and radio buttons

    Hi,

    What can I do so that only the change for the newly selected button is recognised? I don't care about the CheckedChanged state for the currently selected button.
    In each of your events, you would test for the state of the Checked property to see whether you need to display your message or not. i.e:-

    Code:
    Private Sub rdoYearly_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rdoYearly.CheckedChanged
      If rdoYearly.Checked Then
        MsgBox("Yearly")
      End If
    End Sub
    Besides being a visual container for the radio buttons, does the group box server any other purpose, and should code for the group box be included in my code?
    The purpose of the GroupBox is to contain items that are related to each other, so in the case of Radio buttons, only one button can be checked at any one time. The best way to demonstrate what the GroupBox is doing is to add another GroupBox to your form, with addition radio buttons, and you will see that only one Radio button can be checked in each GroupBox and the two groups of Radio Buttons are independent of each other.

    In addition to this the GroupBox, as with all controls in VB, gives you events that can be coded but in your example you do not need to worry about any events being raised by the GroupBox.

    Hope that helps.

    Cheers,

    Ian

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