Erez Savir
Erez Savir

Reputation: 74

Insert value into radiobutton

I'm trying to insert a value into a RadioButton based on a value I have in an array.

This is what I'm trying to acheive, but I can't seem to get it work. I know the IsChecked is a check if the RadioButton is checked or not, but I want to describe the means.

if (arrAnswer[nAnswerNum] == 0)
{
    radioTrue.IsChecked = false;
    radioFalse.IsChecked = false;
}
else if (arrAnswer[nAnswerNum] == 1)
{
    radioTrue.IsChecked = true;

}
else if (arrAnswer[nAnswerNum] == 2)
{
    radioFalse.IsChecked = true;
}

Thanks

Upvotes: 0

Views: 100

Answers (1)

DevEstacion
DevEstacion

Reputation: 1967

Do it like this, it's much simpler

radioTrue.IsChecked = arrAnswer[nAnswerNum] == 1;
radioFalse.IsChecked = arrAnswer[nAnswerNum] == 2;

also dont forget to check if the index does exists to prevent indexoutofrange exception

Upvotes: 1

Related Questions