?
Solved

Bind RadioButtons in vb 2005

Posted on 2007-08-12
5
Medium Priority
?
1,046 Views
Last Modified: 2013-11-05
How do I bind the radio button using the code below? It's asking for the property name and I can't seem to find it....thought it was Checked like a checkbox, but that doesn't work.

RBFemale.DataBindings.Add("Text", CustomerIDTable, "Female")
RBFemale.DataBindings.Add("Checked", CustomerIDTable, "Female")
'RBMale.DataBindings.Add("RadioButton", CustomerIDTable, "Male")
RBFemale.Checked = CBool(CustomerIDTable.Rows(CustomersRowPosition)("Female"))
0
Comment
Question by:mindserve
  • 3
  • 2
5 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 19679112
Is this working:

RBMale.DataBindings.Add("Checked", CustomerIDTable, "Male")
RBFemale.DataBindings.Add("Checked", CustomerIDTable, "Female")

What is the datatype for Male and Female columns?
Are you sure that both fields are not NULL?
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 100 total points
ID: 19679151
if your fields are of type boolean, it is working:

    Private Function CreateDataSet() As DataSet
        'Creates a new dataset, 2 datatables and adds data to them
        Dim dsData As New DataSet("TestDataSet")

        Using dt As New DataTable("Countries")
            dt.Columns.Add("ID", GetType(Integer))
            dt.Columns.Add("Description", GetType(String))
            dt.Columns.Add("Check1", GetType(Boolean))
            dt.Columns.Add("Check2", GetType(Boolean))

            dt.LoadDataRow(New Object() {1, "Canada", False, True}, True)

            dsData.Tables.Add(dt)
        End Using

        Return dsData
    End Function

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim ds As DataSet

        ds = CreateDataSet()

        TextBox1.DataBindings.Add("Text", ds.Tables(0), "ID")
        TextBox2.DataBindings.Add("Text", ds.Tables(0), "Description")
        CheckBox1.DataBindings.Add("Checked", ds.Tables(0), "Check1")
        CheckBox2.DataBindings.Add("Checked", ds.Tables(0), "Check2")
        RadioButton1.DataBindings.Add("Checked", ds.Tables(0), "Check1")
        RadioButton2.DataBindings.Add("Checked", ds.Tables(0), "Check2")
    End Sub
0
 
LVL 1

Author Comment

by:mindserve
ID: 19679152
data type is boolean...
0
 
LVL 1

Author Comment

by:mindserve
ID: 19679188
I forgot this in the load event.....
        If RBMale.Checked = True Then
            RBMale.Text = "M"
        Else
            If RBFemale.Checked = True Then
                RBFemale.Text = "F"
            End If
        End If
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 19679189
try my code and you will se that it is working so it is surely something in your code or in your data
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question