Results 1 to 3 of 3

Thread: [2005] Group Box and Radion Buttons

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    150

    [2005] Group Box and Radion Buttons

    I have radio buttons grouped in a group box


    Question1: Can I give each radio button a default value:

    Example radio1 value = 1 ,radio2 value =2

    If this is possible , How do I get which radio button is selected and what is it's value without using If statement.

    Example : Messagebox.show ---> groupBox Selected radio button Value !

  2. #2
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2005] Group Box and Radion Buttons

    You can do this with the RadioButton's Tag Property

    You can then loop through the controls in the Groupbox to see which one is checked
    Code:
            Dim selectedValue As Integer
            For Each ctl As Control In Me.GroupBox1.Controls
                If TypeOf (ctl) Is RadioButton Then
                    If DirectCast(ctl, RadioButton).Checked Then
                        selectedValue = ctl.Tag
                        Exit For
                    End If
                End If
            Next
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  3. #3
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Group Box and Radion Buttons

    Another way to do it would be to have a routine that handles the check changed event of the radio buttons. Put the value of each radio button that you want them to have in their Tag property and then just have something like this:
    vb Code:
    1. 'Declare variables
    2. Dim RadioValue As String
    3. Dim RadioName As String
    4.  
    5. Private Sub GetButtonValue_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    6.     Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, RadioButton3.CheckedChanged
    7.         'Assign variables the values and use these
    8.         RadioName = DirectCast(sender, RadioButton).Name
    9.         RadioValue = DirectCast(sender, RadioButton).Tag.ToString
    10.  
    11. End Sub
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

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