I'm kind of new at this,
It is a WindowsForm application
I have a group box with 8 Radio buttons in it. What i am trying to do is when i select a radio button from the group i want the text for that radio button to appear in the text box at the bottom of the form. Any ideas?
Loading
Kirtan PatelPosted Feb 17, 2010, 3:33 PM
Here is you super compact code !! to perform desire task :-)
public void RadioButtonChanged(Object Sender, EventArgs e)
{
// Show Radio Button text In Text box
textBox1.Text = ((RadioButton)Sender).Text;
}
private void Form1_Load(object sender, EventArgs e)
{
// Add Event Handlers to All radio Buttons
foreach (Control c in grpBeverages.Controls)
{
if (c is RadioButton)
{
((RadioButton)c).CheckedChanged += new EventHandler(RadioButtonChanged);
}
}
}
kiran kumarPosted Feb 18, 2010, 3:32 AM
MARK THE ANSWER IT HELPS YOU
kiran kumarPosted Feb 18, 2010, 3:27 AM
HERE IS THE CODE FOR YOU KEVIN
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace radlis1lis2
{
public partial class Form1 : Form
{
string[] hi = { "kiran", "kumar" };
string[] hello = { "hi", "kevin" };
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < hi.Length; i++)
{
listBox1.Items.Add(hi[i]);
}
for (int j = 0; j < hello.Length; j++)
{
listBox2.Items.Add(hello[j]);
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
radioButton1.Checked = false;
textBox1.Text += listBox1.SelectedItem.ToString();
}
else
{
textBox1.Text += listBox1.SelectedItem.ToString();
}
}
private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
radioButton1.Checked = false;
textBox1.Text += listBox2.SelectedItem.ToString();
}
else
{
textBox1.Text += listBox2.SelectedItem.ToString();
}
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
textBox1.Text += radioButton1.Text;
}
}
}
}
mark the answer if it helps you
kevinPosted Feb 17, 2010, 10:08 PM
How would i got about selecting a radiobutton and 2 items from list box and showing all 3 in textbox.
kevinPosted Feb 17, 2010, 3:35 PM
Kirtan PatelPosted Feb 17, 2010, 3:09 PM
[email protected]
kevinPosted Feb 17, 2010, 3:00 PM
For ex, i have 8 radio buttons,
btnCoke
btnPepsi
btnDew
btnSprite
btnSevenUp
btnGingerale
btnLemonaid
btnWine
How would the whole code look like? :$
Where would the radiobuttons objects be placed:S
NainilPosted Feb 17, 2010, 2:20 PM
You should have your RadioButton fire the CheckChanged event. Inside of the event, cast the "sender" object as RadioButton and then simply set the Text property of the TextBox control to the RadioButton.Text. Following is the code that you can use:
private void radioButton_CheckedChanged(object sender, EventArgs e)
{
RadioButton oRadioButton = sender as RadioButton;
textBox1.Text = oRadioButton.Text;
}
You can have each of the RadioButton object's CheckChanged event to the above function. That should do it. Hope this helps.