Question

good night. At my solution i have an code that allow me write 5 useful informations about user, like: name, sex, age, weight and height. When was implemented solution to check if sex was M or F i used these code

if (radioButton1.Checked)
            {
                value = radioButton1.Text;
                Convert.ToString(value);


            }
            else if (radioButton2.Checked)
            {
                value = radioButton2.Text;
                Convert.ToString(value);
            }

value is an variable as string type. Now i need an similar code to read, i think that is similar, and i start, building an new class. With the open class, i started by declaring the necessary variables, prepare the constructor and set methods. I have an method called getxmlusersex (), which is specific for sex verification in existing xml and this method have the following code (imagined and planned by me)

  public void getxmlusersex()
        {
            add.sex = xDoc.SelectSingleNode("//Dados//Sexo").InnerText;
            if (add.sex == "M")
            {
                add.sex = form.radioButton1.Text;
                Convert.ToBoolean(form.radioButton1.Text);
            }
            if (add.sex == "F")
            {
                add.sex = form.radioButton2.Text;
                Convert.ToBoolean(form.radioButton2.Text);
            }


        }

When running and check if user exists, the solution print name, age, weight and height but don't print sex type (M or F). So how can i filter if sex is M or F and check this same radiobutton (radiobutton1 or radiobutton2)

Was it helpful?

Solution

You need set RadioButton.Checked property for proper RatioButton. That is how you can achieve this:

add.sex = xDoc.SelectSingleNode("//Dados//Sexo").InnerText;
if (add.sex == "M")
{
    form.radioButton1.Text = "Male"; //if you do not specify text in designer
    form.radioButton1.Checked = true;
}
else if (add.sex == "F")
{
    form.radioButton2.Text = "Female";
    form.radioButton2.Checked = true;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top