Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a checked radio button in a groupbox? [duplicate]

I have a lot of radio buttons in a groupbox. Normally I will check each radio button individually using If radiobutton1.Checked = True Then.

But I think maybe there is smart way to check which radio button being checked in a groupbox. Any idea?

like image 845
Predator Avatar asked Jun 24 '11 11:06

Predator


People also ask

How do you get radio button is checked or not?

Using Input Radio checked property: The Input Radio checked property is used to return the checked status of an Input Radio Button. Use document. getElementById('id'). checked method to check whether the element with selected id is check or not.

How can I get radio button to click?

To check which radio button is selected in a form, we first get the desired input group with the type of input as an option and then the value of this selection can then be accessed by the val() method. This returns the name of the option that is currently selected.

How many radio buttons in a group of can be selected at the same time?

Only one radio button in a given group can be selected at the same time. Radio buttons are typically rendered as small circles, which are filled or highlighted when selected.

How do you test if a radio button is selected Javafx?

You can explicitly make a radio button selected by using the setSelected method and specifying its value as true . If you need to check whether a particular radio button was selected by a user, apply the isSelected method.


1 Answers

try this

Dim rButton As RadioButton = 
        GroupBox1.Controls
       .OfType(Of RadioButton)
       .FirstOrDefault(Function(r) r.Checked = True)

this will return the Checked RadioButton in a GroupBox

Note that this is a LINQ query, and you must have

Imports System.Linq

If you do not, your IDE/Compiler may indicate that OfType is not a member of System.Windows.Forms.Control.ControlCollection

like image 112
Binil Avatar answered Sep 21 '22 18:09

Binil