Well at this point I think it's safe to say coding is not my thing, have another problem I am working on, have the code close to correct I believe, problem, when one of the radio buttons is selected, there should be another groupbox that shows (depending on which radio button) that you can select check boxes from (items), once selections are made you select place order and it displays the correct values. For what ever reason I can not get the values, nor the groupbox with items to display to select from. What am I doing wrong? Thanks in advance!

Partial Public Class frmLunchOrders
    Inherits Form
    Public Sub New()
        InitializeComponent()

    End Sub
    Private Sub radHamburger_CheckedChanged(sender As Object, e As EventArgs)

        If radHamburger.Checked = True Then
            lstOrderDetails.Visible = False

            chkLettuce.Visible = True
            chkKetchup.Visible = True
            chkFrench.Visible = True

            txtSubtotal.Text = ""
            txtTax.Text = ""
            txtOrderTotal.Text = ""
            chkLettuce.Text = "Lettuce, Tomato, and Onions"
            chkKetchup.Text = "Ketchup, Mustard, and Mayo"
            chkFrench.Text = "French Fires"
            grpAddHamburger.Text = "Add-on items ($.75/each)"

            chkLettuce.Checked = False
            chkKetchup.Checked = False

            chkFrench.Checked = False
        End If

    End Sub

    Private Sub radPizza_CheckedChanged(sender As Object, e As EventArgs)
        If radPizza.Checked = True Then
            lstOrderDetails.Visible = False

            chkPepperoni.Visible = True
            chkSausage.Visible = True
            chkOlives.Visible = True
            txtSubtotal.Text = ""
            txtTax.Text = ""
            txtOrderTotal.Text = ""
            chkPepperoni.Text = "Pepperoni"
            chkSausage.Text = "Sausage"
            chkOlives.Text = "Olives"
            grpAddPizza.Text = "Add-on items ($.50/each)"

            chkPepperoni.Checked = False
            chkSausage.Checked = False
            chkOlives.Checked = False
        End If
    End Sub


    Private Sub radSalad_CheckedChanged(sender As Object, e As EventArgs)
        If radSalad.Checked = True Then
            lstOrderDetails.Visible = False

            chkCroutons.Visible = True
            chkBacon.Visible = True
            chkBread.Visible = True

            txtSubtotal.Text = ""
            txtTax.Text = ""
            txtOrderTotal.Text = ""
            chkCroutons.Text = "Croutons"
            chkBacon.Text = "Bacon Bits"
            chkBread.Text = "Bread Sticks"
            grpAddSalad.Text = "Add-on items ($.25/each)"

            chkCroutons.Checked = False
            chkBacon.Checked = False
            chkBread.Checked = False
        End If
    End Sub

    Private Sub btnPlaceOrder_Click(sender As Object, e As EventArgs)

        lstOrderDetails.Visible = True
        btnPlace.Visible = False
        grpMain.Visible = False

        If radHamburger.Checked = True Then

            lstOrderDetails.Items.Add("Hamburger - $6.95")
            Dim subtotal As Double = 6.95

            Dim addOnItems As Double = 0
            If chkLettuce.Checked = True Then
                lstOrderDetails.Items.Add("Lettuce, Tomato, Onion - $0.75")
                addOnItems = addOnItems + 0.75
            End If
            If chkKetchup.Checked = True Then
                lstOrderDetails.Items.Add("Ketchup, Mustard, Mayo - $0.75")
                addOnItems = addOnItems + 0.75
            End If
            If chkFrench.Checked = True Then
                lstOrderDetails.Items.Add("French Fries - $0.75")
                addOnItems = addOnItems + 0.75
            End If



            subtotal = (subtotal + addOnItems)
            Dim tax As Double = subtotal * 0.0775
            Dim orderTotal As Double = subtotal + tax



            txtSubtotal.Text = subtotal.ToString("c")
            txtTax.Text = tax.ToString("c")


            txtOrderTotal.Text = orderTotal.ToString("c")

            lstOrderDetails.Items.Add("---------------------------------------------")
        End If

        If radPizza.Checked = True Then
            lstOrderDetails.Items.Add("Cheese Pizza - $5.95")

            Dim subtotal As Double = 5.95

            Dim addOnItems As Double = 0
            If chkPepperoni.Checked = True Then
                lstOrderDetails.Items.Add("Add Pepperoni - $0.50")
                addOnItems = addOnItems + 0.5
            End If
            If chkSausage.Checked = True Then
                lstOrderDetails.Items.Add("Add Sausage - $0.50")
                addOnItems = addOnItems + 0.5
            End If
            If chkOlives.Checked = True Then
                lstOrderDetails.Items.Add("Add Olives - $0.50")
                addOnItems = addOnItems + 0.5
            End If

            subtotal = (subtotal + addOnItems)

            Dim tax As Double = subtotal * 0.0775
            Dim orderTotal As Double = subtotal + tax


            txtSubtotal.Text = subtotal.ToString("c")
            txtTax.Text = tax.ToString("c")
            txtOrderTotal.Text = orderTotal.ToString("c")

            lstOrderDetails.Items.Add("---------------------------------------------")
        End If

        If radSalad.Checked = True Then
            lstOrderDetails.Items.Add("Salad - $4.95")

            Dim subtotal As Double = 4.95

            Dim addOnItems As Double = 0
            If True Then
                If chkCroutons.Checked = True Then
                    lstOrderDetails.Items.Add("Add Croutons - $0.25")
                End If
                addOnItems = addOnItems + 0.25
            End If
            If chkBacon.Checked = True Then
                lstOrderDetails.Items.Add("Add Bacon Bits - $0.25")
                addOnItems = addOnItems + 0.25
            End If
            If chkBread.Checked = True Then
                lstOrderDetails.Items.Add("Add Bread Sticks - $0.25")
                addOnItems = addOnItems + 0.25
            End If

            subtotal = (subtotal + addOnItems)

            Dim tax As Double = subtotal * 0.0775
            Dim orderTotal As Double = subtotal + tax



            txtSubtotal.Text = subtotal.ToString("c")
            txtTax.Text = tax.ToString("c")
            txtOrderTotal.Text = orderTotal.ToString("c")



            lstOrderDetails.Items.Add("---------------------------------------------")
        End If


        grpTotal.Text = "Order Details"

    End Sub
    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub
    Private Sub clearTotals(sender As Object, e As EventArgs)
        txtSubtotal.Text = ""
        txtTax.Text = ""
        txtOrderTotal.Text = ""
    End Sub

End Class

Recommended Answers

All 2 Replies

you need to manually show or hide your groupbox like this

Private Sub radHamburger_CheckedChanged(sender As Object, e As EventArgs)
    If radHamburger.Checked = True Then
        grp_hamburger.visible=true
        grp_pizza.visible=false
        grp_salad.visible=false
        'rest of the code here
    end if
end sub

Here's a simple way that also simplifies your code:

Partial Public Class frmLunchOrders
    Inherits Form        
    Public Sub New()
        InitializeComponent()
        For Each r As RadioButton In Me.Controls.OfType(Of RadioButton)()
            AddHandler r.CheckedChanged, AddressOf Rad_CheckedChange
        Next
        grpAddPizza.Location = grpAddHamburger.Location
        grpAddSalad.Location = grpAddHamburger.Location
    End Sub
    Private Sub Rad_CheckedChange(ByVal sender As Object, ByVal e As EventArgs)
        Dim CheckedRadBut As RadioButton = DirectCast(sender, RadioButton)
        Dim Category As String = CheckedRadBut.Name.Substring(3)
        Dim Vis As Boolean = CheckedRadBut.Checked            
        Select Case Category
            Case "Hamburger"
                grpAddHamburger.Visible = Vis
            Case "Pizza"
                grpAddPizza.Visible = Vis
            Case "Salad"
                grpAddSalad.Visible = Vis
        End Select            
    End Sub
End Class

Start with all the group boxes Visible property set to False. Everytime the radio button change the appropriate group box is visible. To make it visually more appealing, I made the group boxes all the same size, and placed the controls in the same place. since I couldn't use the designer to place them in the same location, I did it through code. with them in the same location the data just appears to change with any diconcerting movement by the controls.

The checked change event fires twice for every click. By using the Checked property of whichever control triggered the event, the first event will set visible to false of one group box, then the second event will set the visible property to true for the other groupbox.

The same technique of using one handler for all the same type of controls, can be applied to the check boxes too. with a select block to process whichever ones is clicked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.