Home > DeveloperSection > Forums > check radiobuttons and display message in C#
Manoj Bhatt
Manoj Bhatt

Total Post:154

Posted on    August-18-2014 3:25 AM

 C# C# 

 1 Reply(s)
 1191  View(s)
Rate this:

I have a form on which are "listBox1" and "button1". I have two function. The second function adds checkboxes to listbox1 and the first function displays message box. But I don´t know how to write the first function.

Here I want to check which checkbox is checked and write a message:

private void button1_click(object sender, EventArgs e)


    MessageBox.Show("radiobutton: " + rb[i].Text);


Here I create checkboxes: //it´s working

internal void loadSurveys()


    WebClient client2 = new WebClient();

    var json = client2.DownloadString("http://www.test.net/api/surveys/?api_key=123");

    JObject data = JObject.Parse(json);

    var example = JsonConvert.DeserializeObject<Example>(json);

    int y = 5;

    int i = 0;

    RadioButton[] rb = new RadioButton[example.surveys.Length];

    String chkBox_name = "";

    String chkBox_text = "";

    foreach (var survey in data["surveys"].Children())


        rb[i] = new RadioButton();

        rb[i].Location = new Point(5, y);

        rb[i].Name = chkBox_name + survey["id"];

        rb[i].Text = chkBox_text + survey["title"];

        rb[i].AutoSize = true;


        y += 20;




Pravesh Singh

Total Post:412

Posted on    August-18-2014 3:46 AM

Hi Manoj,

private void button1_click(object sender, EventArgs e)


    var rb = this.listBox1.Controls.OfType<RadioButton>().SingleOrDefault(n => n.Checked);

    if (rb != null)

        MessageBox.Show("radiobutton: " + rb.Text);

Don't want to miss updates? Please click the below button!

Follow MindStick