Results 1 to 2 of 2

Thread: Help with radio buttons and text

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    1

    Help with radio buttons and text

    I'm a beginner so please take it easy on me. I was wondering what the code is for the text of ANY selected radio button to appear in the multiline textbox that is already set up. Is that at all possible? If so, can you do the same for check boxes?
    Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help with radio buttons and text

    There's nothing that will automatically get the RadioButton that is currently checked from a group. You just have to test the Checked property of each one in the group until you find one that's True. You can then get the Text of that RadioButton and call AppendText on the TextBox.

    The old-school way would be to use an If...ElseIf block to test each RadioButton. Assuming .NET 3.5 or later, you could use LINQ instead, e.g.
    vb.net Code:
    1. Dim radioButtons = New RadioButton() {Me.RadioButton1, Me.RadioButton2, Me.RadioButton3}
    2. Dim checkedRadioButton = radioButtons.SingleOrDefault(Function(rb) rb.Checked)
    If you know for a fact that one of the RadioButtons will be checked then you can use Single instead of SingleOrDefault and 'checkedRadioButton' will never be Nothing.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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