PC Review


Reply
Thread Tools Rate Thread

Bind data to radiobutton

 
 
Hemang Shah
Guest
Posts: n/a
 
      6th Feb 2005
Hello

I cannot seem to figure out what property do you bind the data to in a
radiobutton ?

I thought we would have to do it on the group box, but group box has only
text & tag properly.

The radio button has an additional CheckAligned property, which is to set
the alignment.

So if I have a boolean value in the dataset "Gender" how do I set it using
1 group and 2 radiobuttons ?

Any help would be appreciated.

Thanks

HS


 
Reply With Quote
 
 
 
 
akim
Guest
Posts: n/a
 
      9th Feb 2005
On Sun, 6 Feb 2005 06:33:33 -0500, Hemang Shah <(E-Mail Removed)> wrote:

> I cannot seem to figure out what property do you bind the data to in a
> radiobutton ?

[...]

> So if I have a boolean value in the dataset "Gender" how do I set it
> using
> 1 group and 2 radiobuttons ?


Hi,

bind any boolean property to the "Checked" property of the
radiobuttons; See example below;

Regards akim

private void Form1_Load(object sender, System.EventArgs e)
{
Test test = new Test(false);
radioButton1.DataBindings.Add("Checked", test, "Male");
radioButton2.DataBindings.Add("Checked", test, "Female");
}




public class Test
{
bool male;
public Test(bool male)
{
this.male = male;
}
public bool Male
{
get{return male;}
}
public bool Female
{
get{return !male;}
}
}
 
Reply With Quote
 
Hemang Shah
Guest
Posts: n/a
 
      10th Feb 2005
Thanks akim

What if I have only one boolean datafield in the database say "gender"

Mostly when you give the options of radio button only one value can be
selected at anytime, and thus only 1 value to be stored in the database.

Thanks

"akim" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> On Sun, 6 Feb 2005 06:33:33 -0500, Hemang Shah <(E-Mail Removed)> wrote:
>
>> I cannot seem to figure out what property do you bind the data to in a
>> radiobutton ?

> [...]
>
>> So if I have a boolean value in the dataset "Gender" how do I set it
>> using
>> 1 group and 2 radiobuttons ?

>
> Hi,
>
> bind any boolean property to the "Checked" property of the
> radiobuttons; See example below;
>
> Regards akim
>
> private void Form1_Load(object sender, System.EventArgs e)
> {
> Test test = new Test(false);
> radioButton1.DataBindings.Add("Checked", test, "Male");
> radioButton2.DataBindings.Add("Checked", test, "Female");
> }
>
>
>
>
> public class Test
> {
> bool male;
> public Test(bool male)
> {
> this.male = male;
> }
> public bool Male
> {
> get{return male;}
> }
> public bool Female
> {
> get{return !male;}
> }
> }



 
Reply With Quote
 
akim
Guest
Posts: n/a
 
      10th Feb 2005
Hi,

never done that before.. sorry. Just an idea (may be a little hackish):
Derive a control from RadioButton. Add a new property
"Unchecked" which inversely wraps the "Checked" property:

public bool Unchecked
{
get{return !Checked;}
set{Checked = !value;}
}

and bind

radioButton1.DataBindings.Add("Checked", test, "Male");
inverseRadioButton1.DataBindings.Add("Unchecked", test, "Male");

If you find a more elegant way let me know

akim




On Wed, 9 Feb 2005 19:50:39 -0500, Hemang Shah <(E-Mail Removed)> wrote:

> What if I have only one boolean datafield in the database say "gender"
> Mostly when you give the options of radio button only one value can be
> selected at anytime, and thus only 1 value to be stored in the database.


---------------------

>> bind any boolean property to the "Checked" property of the
>> radiobuttons; See example below;


>> private void Form1_Load(object sender, System.EventArgs e)
>> {
>> Test test = new Test(false);
>> radioButton1.DataBindings.Add("Checked", test, "Male");
>> radioButton2.DataBindings.Add("Checked", test, "Female");
>> }
>>
>> public class Test
>> {
>> bool male;
>> public Test(bool male)
>> {
>> this.male = male;
>> }
>> public bool Male
>> {
>> get{return male;}
>> }
>> public bool Female
>> {
>> get{return !male;}
>> }
>> }


---------------

>>> I cannot seem to figure out what property do you bind the data to in a
>>> radiobutton ?
>>> So if I have a boolean value in the dataset "Gender" how do I set it
>>> using 1 group and 2 radiobuttons ?

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
groupbox and radiobutton relationship - which radiobutton is check =?Utf-8?B?UmljaA==?= Microsoft VB .NET 2 30th Jan 2007 04:56 PM
Bind ApplicationSettings to RadioButton Uwe Braunholz Microsoft Dot NET Framework Forms 0 28th Nov 2006 09:45 PM
Bind data to radiobutton Hemang Shah Microsoft Dot NET Framework Forms 3 10th Feb 2005 07:43 AM
asp.net radiobutton doesnt recognize jscript function, but html radiobutton will moondaddy Microsoft ASP .NET 10 30th Mar 2004 04:02 PM
Using data to name a radioButton control John Holmes Microsoft ASP .NET 2 4th Feb 2004 04:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:47 AM.