Binding Radio Buttons
-
Saturday, September 01, 2012 12:30 PM
I have three radio boxes
rbCash, rbCheque, rbVisa
How do I bind them to one field H_25PaidBy. ( bsHeader).
Thanks in advance
All Replies
-
Saturday, September 01, 2012 12:49 PM
As you know radioButton can have 2 states: checked or unchecked (so you can pass boolean type, or integer, even some string conversion can be possible).
So, what kind type of data you wanna bind to these controls?
You can check here how you can do the binding: http://stackoverflow.com/questions/675137/best-way-to-databind-a-group-of-radiobuttons-in-winforms
Mitja
-
Saturday, September 01, 2012 1:02 PM
I would like to have it so that
if (rbcash.checked) H_25PaidBy = "1"
if (rbCheque.checked) H_25PaidBy = "2"
if (rbVisa.checked) H_25PaidBy = "3"
H_25PaidBy. ( bsHeader).
-
Saturday, September 01, 2012 1:22 PM
H_25PaidBy
H_25PaidBy
H_25PaidBy
are what fields? Fileds where? In datatable, database? Where? You have to be specific.
thx
Mitja
-
Saturday, September 01, 2012 3:40 PM
Sorry - I always assume people can read my mind.
H_25PaidBy is a field in a datatable that has a bindingsource bsheader
-
Saturday, September 01, 2012 4:21 PM
You can do the following:
DataTable table; public Form1() { InitializeComponent(); table = new DataTable(); table.Columns.Add("H_25PaidBy", typeof(string)); table.Rows.Add("1"); //default value (1st checked RadioButton[] rbs = new[] { radioButton1, radioButton2, radioButton3 }; foreach (var c in rbs) c.CheckedChanged += new EventHandler(c_CheckedChanged); } private void c_CheckedChanged(object sender, EventArgs e) { RadioButton r = sender as RadioButton; if (r != null) { if (r.Checked) { switch (r.Name) { case "radioButton1": table.Rows[0]["H_25PaidBy"] = "1"; break; case "radioButton2": table.Rows[0]["H_25PaidBy"] = "2"; break; case "radioButton3": table.Rows[0]["H_25PaidBy"] = "3"; break; } } } }
Mitja
- Edited by Mitja BoncaMicrosoft Community Contributor Saturday, September 01, 2012 4:23 PM
- Marked As Answer by CanAnn Tuesday, September 04, 2012 1:30 PM


