RadioButtons, like the station selection buttons on a car radio, are designed to be used in a set. That set demands that the end user make a definitive choice among several mutually exclusive alternatives. In that regard, a set of RadioButtons presents the user with the same rules of usage put forward by a ComboBox, or a ListBox with its MultiSelect property set to False. But a set of RadioButtons represents a particularly elegant and intuitive control, and when you have the screen space for it, may provide the end user experience you really want.
It imposes a different set of coding demands, however, compared to the ComboBox and the ListBox, since the latter are individual controls, whereas a set of RadioButtons is a collection of individual controls. ASP.NET provides a RadioButtonList control that encapsulates the desired functionality in a single control, but there is no corresponding control in the WinForm control set. How on earth does one bind a single property to a collection of RadioButtons?
In raw .NET, you don't. Either you must use the Radio buttons unbound, writing code to check and uncheck them as you navigate among your business objects; or find (or create) a custom equivalent of the ASP.NET RadioBoxList.
With DevForce, you already have what you need. Here's how you bind to your RadioButton set:
- Drag a container control (GroupBox, Panel, etc.) on to the target Form or UserControl. 2.
- Populate the container control with a set of RadioButtons -- one for each of the possible values of the business object property you intend to bind.
- Set the value of the Tag property for one of the RadioButtons to one of the possible values of the targetted business object property. Do the same for the remaining RadioButtons, until each possible value that the business object property can take on is represented by exactly one RadioButton.
You can set the Tag property values in the Visual Studio WinForm designer, or in code. Here's a code example:
|