Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / May 2007

Tip: Looking for answers? Try searching our database.

How do you bind to a group of radio buttons in Windows Forms?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
teddysnips@hotmail.com - 15 May 2007 14:14 GMT
Back in the dim mists of antiquity I used to program in VBA for
Microsoft Access (hey, don't knock it - very useful tool for the right
application).

This had a really handy control in the toolbox called an Option
Group.  It could contain any number of radio buttons (which Access
called Option Buttons), each of which had a "value" property.  The
Option Group as a whole had a property equal to the value of the
selected radio button.  Thus you could bind the group to a single
datum.

Example.  Let's say a "Person" record contains a column called
"PreferredTransport" (type = integer).  This can take any of three
values:

0 = Car
1 = Train
2 = Bus

How simple, therefore, to create an OptionGroup called "Transport",
with three radio buttons as above and set it according to the value of
the "PreferredTransport" column.

Why isn't this available out of the box in C# for Windows Forms? Does
anyone know of a site where I could get an example of a workaround?  I
know I can do it the hard way - either binding each radio button on my
form to a separate datum, or having unbound radio buttons and
explicitly setting and getting the values, but it's all a bit
laborious.

Many thanks

Edward
Nicholas Paldino [.NET/C# MVP] - 15 May 2007 14:31 GMT
Actually, I think it would be kind of easy.  You can derive from
RadioButton and provide a Value property which has the value that you want
that RadioButton to have.

   Then, have a class derived from Panel (or some other container control)
which has a Value property.  It would cycle through its controls and for
every type of that derived radio button class that it has, it would check to
see if the radio button is checked.  If it is, it returns that value.

   Hope this helps.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Back in the dim mists of antiquity I used to program in VBA for
> Microsoft Access (hey, don't knock it - very useful tool for the right
[quoted text clipped - 29 lines]
>
> Edward
teddysnips@hotmail.com - 15 May 2007 14:49 GMT
On May 15, 2:31 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.com> wrote:
>     Actually, I think it would be kind of easy.  You can derive from
> RadioButton and provide a Value property which has the value that you want
[quoted text clipped - 6 lines]
>
>     Hope this helps.

It helps, in the sense that it tells me how to achieve my goal, or at
least gives me directions for landfall at least.  What's truly
irritating is that IMHO this should be provided in the toolbox, since
groups of mutually exclusive option/radio buttons are pretty well
universal in UI design.  I know some people think that drop-down lists
are better, but they're not, unless you have a lot of options (such as
a list of countries).

Oh well, back to the grindstone.

Cheers

Edward
Johnny Jörgensen - 16 May 2007 08:16 GMT
Maybe you can use this:

http://www.codeproject.com/cs/combobox/RadioListBox.asp

It's looks quite nice, actually, but I haven't tested it yet

Cheers,
Johnny J.

> Back in the dim mists of antiquity I used to program in VBA for
> Microsoft Access (hey, don't knock it - very useful tool for the right
[quoted text clipped - 29 lines]
>
> Edward

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.