Bind RadioButtons in vb 2005

Posted on 2007-08-12
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"))
Question by:mindserve
    LVL 69

    Expert Comment

    by:Éric Moreau
    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?
    LVL 69

    Accepted Solution

    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)

            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
    LVL 1

    Author Comment

    data type is boolean...
    LVL 1

    Author Comment

    I forgot this in the load event.....
            If RBMale.Checked = True Then
                RBMale.Text = "M"
                If RBFemale.Checked = True Then
                    RBFemale.Text = "F"
                End If
            End If
    LVL 69

    Expert Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Title # Comments Views Activity
    C# ConsolApp opens new window 16 43
    Help file 1 28
    vb linq Count Distinct? 1 29
    Whats wrong with this query 21 22
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    This video teaches viewers about errors in exception handling.
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now