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?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With