Databinding Radio Buttons in VB.NET

Bob721

Member
Joined
Oct 15, 2007
Messages
6
Programming Experience
Beginner
The best way to visualize my question is to think of how Microsoft Access handles radio option buttons. In Access, when you put in radio button controls, each one is given a unique, numerical value. When the radio button is selected, its numerical value is stored in the table behind the form.

I'm looking for this same functionality in VB.NET. I believe I have all the data bindings correct (i.e. – sqlconnection, sqldataadapter, and dataset ), but I'm struggling with the code that needs to give each radio button control its unique, numerical value; and most importantly, how to get it to store that value in the back-end table on the SQL Server (not just use the value in a message on the screen like most of the radio button examples on the internet). Any help would be greatly appreciated!
 
SqlConnections and SqlDataAdapters have nothing whatsoever to do with data-binding. Data-binding takes place between a control and a data source, which is most usually a list of some description. That data source may be a DataSet but it certainly doesn't have to be. Even if it is a DataSet, the data in it need not have come from a database. Data access and data binding are often used in concert but they are two distinct operations.

What you're asking for is simply not possible as is. The property of interest with a RadioButton is Checked, which is type Boolean. That means that you can really only bind a true/false value to the control. That's not really any use though, because the database value will, as you say, be one a several numerical values.

What you should do is create your own UserControl. You can then place any number of RadioButtons on that control. You would define a property in the UserControl to which you could bind your data. Within the getter and setter of that property you would then translate between the number in the bound data and the radioButton that was checked on the control.
 
Thank you for clarifying data access and databinding - what you said makes good sense now that I think about it. I will attempt to create a UserControl like you suggested, but it would be nice to have an example to reference if possible. Do you have anything like this by chance?

Either way, thanks again for your help!
 
Back
Top