---
title: "check radiobuttons and display message in C#"  
description: "check radiobuttons and display message in C#"  
author: "Manoj Bhatt"  
published: 2014-08-18  
updated: 2014-08-18  
canonical: https://www.mindstick.com/forum/2052/check-radiobuttons-and-display-message-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# check radiobuttons and display message in C#

I have a [form](https://www.mindstick.com/forum/6/multi-form-mfc-application) on which are "listBox1" and "button1". I have two [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server). The [second](https://answers.mindstick.com/qa/41761/how-did-the-second-industrial-revolution-influence-women-s-roles-in-society) function adds checkboxes to listbox1 and the first function displays [message](https://www.mindstick.com/forum/12802/show-confirmation-message-yes-or-no-in-asp-dot-net) box. But I don´t know how to write the first function.

Here I want to [check](https://yourviews.mindstick.com/story/2248/never-forget-to-check-these-specifications-before-buying-a-mobile-phone) which [checkbox](https://www.mindstick.com/articles/291/how-should-use-checkbox-control-in-vb-dot-net) 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 workinginternal 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;        this.listBox1.Controls.Add(rb[i]);        y += 20;        i++;    }}
```

## Replies

### Reply by Pravesh Singh

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);} 
```

\


---

Original Source: https://www.mindstick.com/forum/2052/check-radiobuttons-and-display-message-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
