Reputation: 21
I have a list of RadioButton : RadioButton1 RadioButton2 RadioButton3 And I want to "Checked" one of this RadioButton using a variable : string nameCheckBox = "RadioButton"+1; And finally I want to do : nameCheckBox.IsChecked = true;
Is it possible ?
Upvotes: 1
Views: 2435
Reputation: 5325
Yes it is, but you have to make sure each RadioButton has a Name or an x:Name
int index = 1; // 1, 2 or 3 in your case
object element = FindName(string.Concat("RadioButton", index));
if (element != null && element.GetType() == typeof(RadioButton))
((RadioButton)element).IsChecked = true;
You can do the same thing for a CheckBox just replace RadioButton with CheckBox
Upvotes: 4