Can a group box (or panel) with radio buttons be data bind?

LarrySevilla

New member
Joined
Oct 15, 2006
Messages
4
Programming Experience
Beginner
I have an 'integer' data field "ColorCode" in a table "Colors". Its values are limited to the following (not necessary consecutive):
11 - Red
22 - Blue
33 - Yellow
44 - Green

Can I do the following?

1. Create a group box (or panel)
2. Create four radio buttons for the colors
3. Bind the group box to ColorCode field

If I select/check the Yellow button, 33 will be stored in the ColorCode field.

Or if the value of ColorCode field is 22, the Blue radio button will be selected/checked.

How?

Pls Help...


Larry Sevilla
VB2005 Novice User
 
Not as far as I know. Instead, I would add an integer tag to each of the buttons. Upon change of a radio item, if the RB is checked, then i would query the relevant BindingSource for its Current item and set the column = the currect radio button tag.

Upon list changed or position changed on the binding source events (i forget which) loop through the controls finding the one whose tag is the same value as the current item column, and check that one


alternately you can create your own hosting control:
http://msdn.microsoft.com/msdnmag/issues/04/07/AdvancedBasics/


I'd be surprised if noone has invented this particular wheel ina reusable fashion, but i didnt look that far
 
I considered another way you can fake it, using a ListBox - bind the Listbox to a datasource that has all possible values. Bind the listbox selected value to the data table, set the lsit to single selection mode and if it really bothers you, alter the appearance of the list so it has a grey background and images for each item that either look like a filled or non filled radio button.

Personally, i'd just leave it as a list, or use a Combo :) - rearrange the UI if necessary
 
You could create your own UserControl and create the data-binding code yourself, then use instances of your control wherever needed. It wouldn't be worth it for a one-off though.
 
Back
Top