Your approach is, in my opinion, flawed.
RadioButton has no "text" attribute, it has "content"
This is how I would do it, (you will ofc populate the ArrayList/Array/List from the database.
DO DB CALLS AS FEW TIMES AS POSSIBLE!!! -This is to limit the bandwidth use
Working example:
C#:
using System.Collections;
using System.Windows;
using System.Windows.Controls;
namespace ExperimentationProject
{
public partial class MainWindow : Window
{
public string inputAnswer;
public string AnswerNum = "1";
public string Question = "Who is the current President of the U.S.?";
public MainWindow()
{
InitializeComponent();
ArrayList Answers = new ArrayList();
Answers.Add("1. Barack Obama");
Answers.Add("2. The Govinator");
Answers.Add("3. Queen Elizabeth II");
Answers.Add("4. Justin Bieber");
groupBox1.Header = Question;
radioButton1.Content = Answers[0];
radioButton2.Content = Answers[1];
radioButton3.Content = Answers[2];
radioButton4.Content = Answers[3];
}
private void button1_Click(object sender, RoutedEventArgs e)
{
if (inputAnswer.Substring(0, 1) == AnswerNum)
{
MessageBox.Show("CORRECT!\n your anser was: " + inputAnswer);
}
else
{
MessageBox.Show("wrong!");
}
}
private void radioButton_Checked(object sender, RoutedEventArgs e)
{
RadioButton RadBtn = sender as RadioButton;
if (RadBtn.IsChecked.Value)
inputAnswer = RadBtn.Content.ToString();
}
}
}
WPF:
<window x:class="ExperimentationProject.MainWindow" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="300" Width="240">
<grid>
<groupbox header="groupBox1" height="245" horizontalalignment="Left" margin="12,12,0,0" name="groupBox1" verticalalignment="Top" width="200" cliptobounds="True">
<grid>
<radiobutton content="RadioButton" height="16" horizontalalignment="Left" margin="6,6,0,0" name="radioButton1" verticalalignment="Top" checked="radioButton_Checked " />
<radiobutton content="RadioButton" height="16" horizontalalignment="Left" margin="6,28,0,0" name="radioButton2" verticalalignment="Top" checked="radioButton_Checked " />
<radiobutton content="RadioButton" height="16" horizontalalignment="Left" margin="6,50,0,0" name="radioButton3" verticalalignment="Top" checked="radioButton_Checked " />
<radiobutton content="RadioButton" height="16" horizontalalignment="Left" margin="6,72,0,0" name="radioButton4" verticalalignment="Top" checked="radioButton_Checked " />
<button content="Button" height="23" horizontalalignment="Left" margin="52,94,0,0" name="button1" verticalalignment="Top" width="75" click="button1_Click" />
</grid>
</groupbox>
</grid>
</window>
The code should be self-explanatory, but notice the -Checked="radioButton_Checked "- that is identical in all the radiobuttons, and the event handler for it. And look at the ".substring(0,1)" those are the only "magic" in this code.
Hope this is helpful!
(remember to accept valid solutions and rate answers appropriately)
-Frank