Reputation: 1275
Ok, I asked this question and got excellent code example as answer. The code works but I don't understand the meaning of the code. Can someone point the direction for me for further reading in order to understand the code. Here is the code that retrieves the checked radio button in a groupbox:
Dim rButton As RadioButton = GroupBox1.Controls _
.OfType(Of RadioButton)() _
.Where(Function(r) r.Checked = True) _
.FirstOrDefault()
Ok, the parts that I don't understand are .OfType
, .Where
, .FirsrOrDefault
UPDATE:
Thanks guys, those things are LINQ
Upvotes: 1
Views: 245
Reputation: 13188
This code selects the first checked radio button in a group of buttons. Lets walk through the code:
Dim rButton As RadioButton = GroupBox1.Controls _
Select the group of form controls
OfType(Of RadioButton)() _
But only the Radio buttons from that group
Where(Function(r) r.Checked = True) _
That are already checked
.FirstOrDefault()
Return the first one or NULL if none are checked.
Upvotes: 5
Reputation: 241611
The code almost reads exactly what it is doing: from the controls on GroupBox1
that are of type RadioButton
, take those where the radio button is checked, and then take the first one (or null
if there aren't any).
In plainer English, among all the radio buttons in the group box, find the first checked one, or return null
if there aren't any.
The methods come from LINQ.
Upvotes: 7
Reputation: 3888
Basically, its going through the controls in GroupBox1 that are OfType radiobutton, and Where they are checked, grabbing the First result or Default/None if there are no results.
Upvotes: 1