Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > databind text property of a set of radiobuttons in a groupbox
 

databind text property of a set of radiobuttons in a groupbox

Is there an easy way to bind the text property of a set o radiobuttons in a groupbox in such a way that the selected radiobutton text property binds to a particular field in a dataset ?

Thank you in advance for your input.

Regards,
Pedro Costa
MigrationUser 1  Thursday, August 07, 2003 1:13 PM
Probably not in any meaningful way: you'd have to write some code to give you properties that you can work with.  Something like this works, but it might not behave the way you want (try it and see).  Note that it's making some pretty big assumptions (you have only RadioButtons in the groupbox and that at least one is checked).


private void Form1_Load(object sender, System.EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("abc");
for (int i=0; i<10; i++)
dt.Rows.Add(new object[] {"val" + i});
dataGrid1.DataSource = dt;
this.DataBindings.Add("CheckedText", dt, "abc");
}

public string CheckedText
{
get 
{
return CheckedRadioButton.Text;
}
set 
{
CheckedRadioButton.Text = value;
}
}

public RadioButton CheckedRadioButton 
{
get 
{
foreach (RadioButton rb in groupBox1.Controls)
{
if (rb.Checked)
return rb;
}
return null;
}
}
MigrationUser 1  Friday, August 08, 2003 5:45 PM

You can use google to search for other answers

Custom Search

More Threads

• Dataset designer - how to debug "Column requires a valid DataType. "
• databinding in C#
• DataGridView population of non-bound columns
• Change colour of modified datagrid row
• forms
• tableadapter + connection pooling + corrupt connections in pool
• serious problem with BindingManagerBase and its definitly a bug
• Windows Service "STOP" not working in On_STOP event of the timer.
• DataGridView Column DateTimePicker BorderStyle
• how can i check textbox contain alphabet?