none
Radio Buttons In Visual Basic 2010 Express

    Question

  • Hi Good People

    I have a form in design view with 3 Radio Button, (Code's Below) And when the form loads I want the Vehicle_RequiredRadioButton to be checked, and in the Database Show 4 Seater, But if the RadioButton1 is checked, Then the Database should show 6 Seater, and If RadioButton2 is Checked Then DataBase should Show 8 Seater. and when I click the save Button, I want the dataBase To Show which of the 3 Radio Button was checked.

    I  dont know if the code's Below is right

     Private Sub BookingForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    
      'TODO: This line of code loads data into the 'GarysTaxiProgramDataBaseDataSet1.RecordsTable1' table. You can move, or remove it, as needed.
    
      Me.RecordsTable1TableAdapter.Fill(Me.GarysTaxiProgramDataBaseDataSet1.RecordsTable1)
    
      Vehicle_RequiredRadioButton .Checked =True 
    
     End Sub
    
    

     

     Private Sub Vehicle_RequiredRadioButton_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles Vehicle_RequiredRadioButton.CheckedChanged
            If Vehicle_RequiredRadioButton.Checked = True Then
                Vehicle_RequiredRadioButton.Text = "4 Seater"
            ElseIf RadioButton1.Checked = True Then
                Vehicle_RequiredRadioButton.Text = "6 Seater"
            ElseIf RadioButton2.Checked = True Then
                Vehicle_RequiredRadioButton.Text = "8 Seater"

            End If
        End Sub

    Kind Regards

    Gary


    Gar
    Thursday, March 31, 2011 1:39 PM

Answers

  • Hi Gary,

    This is my understanding of your situation.  Hopefully I interpreted it correctly.

      - You have the three radiobuttons
      - You have a database that you wish to query and return results based on which radiobutton is selected
      - Presumably you have a datagridview bound to "Me.GarysTaxiProgramDataBaseDataSet1.RecordsTable1"

    To do this you will need to create a "FillBy" query.  Presumably your database table has a field in it that specifies the number of seats;  for the sake of this discussion I am going to assume that the field is named "NumSeats".

    Ok now for the fun part. Creating the query.

    1.  Open then "Solution Explorer".  "View Menu->Solution Explorer"
    2.  Double-Click on "GarysTaxiProgramDataBaseDataSet1.xsd".  This should open the data set designer.
    3.  You should see a table named "RecordsTable1", Right-Click on RecordsTable1TableAdapter and select Add->Query.
        This should bring up the "TableAdapter Query Configuration Wizard".
    4.  Select "Use SQL statements" and click "Next".
    5.  Select "Select wjich returns rows" and click "Next".
    6.  Click on "Query Builder".
    7.  Select the row which contains "NumSeats" or whatever you have named it.
    8.  Goto the column labeled "Filter" and enter "=?" without the quotes. Click "OK" and then Click "Finish".
    9.  Close the "DataSet Designer" window and answer "yes" to saving the changes.

    10. Now under the Radiobutton logic do something like this:

    Private Sub Vehicle_RequiredRadioButton_CheckedChanged(sender As System.Object, e As System.EventArgs) _
       Handles Vehicle_RequiredRadioButton.CheckedChanged
            If Vehicle_RequiredRadioButton.Checked = True Then
                Vehicle_RequiredRadioButton.Text = "4 Seater"
                Me.RecordsTable1TableAdapter.FillBy(Me.GarysTaxiProgramDataBaseDataSet1.RecordsTable1, 4)
            ElseIf RadioButton1.Checked = True Then
                Vehicle_RequiredRadioButton.Text = "6 Seater"
                Me.RecordsTable1TableAdapter.FillBy(Me.GarysTaxiProgramDataBaseDataSet1.RecordsTable1, 6)
            ElseIf RadioButton2.Checked = True Then
                Vehicle_RequiredRadioButton.Text = "8 Seater"
                Me.RecordsTable1TableAdapter.FillBy(Me.GarysTaxiProgramDataBaseDataSet1.RecordsTable1, 8)

            End If
    End Sub

    11. You may want to delete:
        Me.RecordsTable1TableAdapter.Fill(Me.GarysTaxiProgramDataBaseDataSet1.RecordsTable1)
        if the load event handler.


    • Marked as answer by Gary Simpson Thursday, March 31, 2011 8:00 PM
    Thursday, March 31, 2011 5:58 PM

All replies

  • Hi,

    You should change it like this:

     Private Sub Vehicle_RequiredRadioButton_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles Vehicle_RequiredRadioButton.CheckedChanged, Radiobutton1.CheckedChanged, RadioButton2.CheckedChanged
        If Vehicle_RequiredRadioButton.Checked = True Then
          Vehicle_RequiredRadioButton.Text = "4 Seater"
        ElseIf RadioButton1.Checked = True Then
          Vehicle_RequiredRadioButton.Text = "6 Seater"
        ElseIf RadioButton2.Checked = True Then
          Vehicle_RequiredRadioButton.Text = "8 Seater"
    
        End If
      End Sub
    Thursday, March 31, 2011 2:05 PM
  • Hi Sparrow.

    Maybe I didn't express My question Properly.

    I have a form in design view with 3 Radio Button, (Code's Below) And when the form loads I want the Vehicle_RequiredRadioButton to be checked,.... and in the Database Show 4 Seater, But if the RadioButton1 is checked,..... Then the Database should show 6 Seater, and If RadioButton2 is Checked Then DataBase should Show 8 Seater...... and when I click the save Button, I want the dataBase To Show which of the 3 Radio Button was checked.

    Best Regards

    Gary


    Gary Simpson
    Thursday, March 31, 2011 3:54 PM
  • Hi Gary,

    This is my understanding of your situation.  Hopefully I interpreted it correctly.

      - You have the three radiobuttons
      - You have a database that you wish to query and return results based on which radiobutton is selected
      - Presumably you have a datagridview bound to "Me.GarysTaxiProgramDataBaseDataSet1.RecordsTable1"

    To do this you will need to create a "FillBy" query.  Presumably your database table has a field in it that specifies the number of seats;  for the sake of this discussion I am going to assume that the field is named "NumSeats".

    Ok now for the fun part. Creating the query.

    1.  Open then "Solution Explorer".  "View Menu->Solution Explorer"
    2.  Double-Click on "GarysTaxiProgramDataBaseDataSet1.xsd".  This should open the data set designer.
    3.  You should see a table named "RecordsTable1", Right-Click on RecordsTable1TableAdapter and select Add->Query.
        This should bring up the "TableAdapter Query Configuration Wizard".
    4.  Select "Use SQL statements" and click "Next".
    5.  Select "Select wjich returns rows" and click "Next".
    6.  Click on "Query Builder".
    7.  Select the row which contains "NumSeats" or whatever you have named it.
    8.  Goto the column labeled "Filter" and enter "=?" without the quotes. Click "OK" and then Click "Finish".
    9.  Close the "DataSet Designer" window and answer "yes" to saving the changes.

    10. Now under the Radiobutton logic do something like this:

    Private Sub Vehicle_RequiredRadioButton_CheckedChanged(sender As System.Object, e As System.EventArgs) _
       Handles Vehicle_RequiredRadioButton.CheckedChanged
            If Vehicle_RequiredRadioButton.Checked = True Then
                Vehicle_RequiredRadioButton.Text = "4 Seater"
                Me.RecordsTable1TableAdapter.FillBy(Me.GarysTaxiProgramDataBaseDataSet1.RecordsTable1, 4)
            ElseIf RadioButton1.Checked = True Then
                Vehicle_RequiredRadioButton.Text = "6 Seater"
                Me.RecordsTable1TableAdapter.FillBy(Me.GarysTaxiProgramDataBaseDataSet1.RecordsTable1, 6)
            ElseIf RadioButton2.Checked = True Then
                Vehicle_RequiredRadioButton.Text = "8 Seater"
                Me.RecordsTable1TableAdapter.FillBy(Me.GarysTaxiProgramDataBaseDataSet1.RecordsTable1, 8)

            End If
    End Sub

    11. You may want to delete:
        Me.RecordsTable1TableAdapter.Fill(Me.GarysTaxiProgramDataBaseDataSet1.RecordsTable1)
        if the load event handler.


    • Marked as answer by Gary Simpson Thursday, March 31, 2011 8:00 PM
    Thursday, March 31, 2011 5:58 PM
  • Hi TnTinMN,

    Thank you very much for your imput, your are a great help in writing the code for me. I am sorry that my Question/Questions are not very good in explaining what I need But Hey You Guy's Understand somehow I dont know how but you do, Thanks Again TnTinMN.

    Best Regards

    Gary


    Gary Simpson
    Thursday, March 31, 2011 8:07 PM
  • Hi Gary,

    I received a notification that you were having some difficulty, but that post seems to have been deleted.  Did you figure it out on your own and just delete that post?  If you still need assistance, just ask.

    Friday, April 01, 2011 1:51 AM
  •  

     

    Hi TnTinMN,

    CAN YOU PLEASE TELL ME THE BEST WAY AROUND THIS CONCEPTS ( There are pictures of the form's Below)

    I have some code to write that involves some daunting concepts, I am trying to write a program for my mate, as you have probably gathered it is a private Hire /taxi Booking program.

    I have a Booking Form, and a Fares Form, what I need is for the booking Form to read a fare off of the Fares Form/Table,  i.e. after typing in or selecting the addresses on the Booking Form in the Destination_FromComboBox & Destination_ToComboBox, I would like the fare to be show in a FareTextbox on the booking form, From the Fares Form.

    If the Vehicle_RequiredRadioButton1 is checked, I would like the FareTextbox to show the value of Normal_FareTextBox from the Fares Form/Table

    And if Vehicle_RequiredRadioButton2 is checked, I would like the FareTextbox to show the value of Normal_Fare6TextBox, from the Fares Form/Table.

    And if Vehicle_RequiredRadioButton3 is checked, I would like the FareTextbox to show the value of Normal_Fare8TextBox from the Fares Form/Table.

    Also there is a time factor, let’s say the time is between 05:00 & 23:59, and Vehicle_RequiredRadioButton1 is selected, then a Normal_FareTextBox value will be shown from the Fares Form/Table. But if the RadioButton1 is selected then the Normal_Fare6TextBox value will be shown from the Fares Form/Table. But if the Vehicle_RequiredRadioButton3 is selected then Normal_Fare8TextBox value will be shown from the Fares Form/Table.

    But if the time is between 00:00 & 01:59 and the Vehicle_RequiredRadioButton1 is selected, then the Time_Half_FareTextBox value will be shown from the Fares Form/Table. But if the Vehicle_RequiredRadioButton2 is selected then the Time_Half_Fare6TextBox value will be shown from the Fares Form/Table. But if the Vehicle_RequiredRadioButton3 is selected then Time_Half_Fare8TextBox   Value will be shown from the Fares Form/Table.  

    But if the time is between 02:00 & 05:00 and the Vehicle_RequiredRadioButton1 is selected, then the Double_FareTextBox Value will be shown from the Fares Form/Table. But if the Vehicle_RequiredRadioButton2 is selected then the Double_Fare6TextBox Value will be shown from the Fares Form/Table. But if the Vehicle_RequiredRadioButton3 is selected then the Double_Fare8TextBox Value will be shown from the Fares Form/Table.

    And after all this, if the addresses typed into Destination_FromComboBox & Destination_ToComboBox does not exist I would like that address to be inserted into the fares form

     

    Photobucket Photobucket
    Gary Simpson
    Friday, April 01, 2011 4:50 PM