jeudi 21 avril 2016

Get index of a selected RadioButton in radioGroup

i want to find an index of a selected RadioButton in RadioGroup. I attached next single method to each RadioButton in the group:

private void radio_button_CheckedChanged(object sender, EventArgs e){
    if (sender.GetType() != typeof(RadioButton)) return;
    if (((RadioButton)sender).Checked){
        int ndx = my_radio_group.Controls.IndexOf((Control)sender);
        // change something based on the ndx
    }
}

It is important to me that lower radioButton must have lower index, starting from zero. And seems it is working, but i am not sure if this is a good solution. Maybe there is more betufilul way to do the same.




Aucun commentaire:

Enregistrer un commentaire