All, I have a GroupBox
with multiple controls (Button
s, RadioButton
s etc.) and I want to know the most efficent way of establishing which RadioButton
in the GroupBox
is in the checked state. I currently have
int nCheckedRadioIdx = 0;
foreach (Control ctrl in groupBoxList.Controls)
{
if (ctrl.GetType() == typeof(RadioButton))
{
if (((RadioButton)ctrl).Checked)
{
switch (((RadioButton)ctrl).Name)
{
case "radioButtonGoodCodeSumm":
nCheckedRadioIdx = 0;
break;
case "radioButtonBadCodeSumm":
nCheckedRadioIdx = 1;
break;
case "radioButtonBadByEpiNo":
nCheckedRadioIdx = 2;
break;
case "radioButtonValidCodes":
nCheckedRadioIdx = 3;
break;
default:
break;
}
break;
}
}
}
I then use an enumerator to establish which button I need. This seems very verbose to me (in fact damn ugly!). I have seen this done in VB with some sort of LINQ query (SO Question) but I have never worked with VB or LINQ and am struggling with the conversion. If there is an even better way that would be great as one of the GroupBox
s contains a significant number of RadioButton
s - I would like to use LINQ for this if possible?