如何从选中的列表框中获取选定的项目并计算它们的总数

How to get selected items from checked list box and compute their total

这是我的设计界面图片:Design Interface

我希望用户进行选择并输入他们希望购买的数量,然后在完成后按计算,它会根据输入的数量给出所选项目的总和,并将总计输入价格文本框。

这是我的代码... 我卡住了...

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
    Me.Close()

End Sub

Public Sub frmDrinks_Load(sender As Object, e As EventArgs) Handles MyBase.Load


End Sub

Public Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
    Dim tMango As Integer
    Dim tOrange As Integer
    Dim tStrawberry As Integer
    Dim tWatermelon As Integer
    Dim tMinty As Integer
    Dim tCoke As Integer
    Dim tDiet As Integer
    Dim tSprite As Integer
    Dim tMineral As Integer
    Dim tSpark As Integer
    Dim tManSmooth As Integer
    Dim tBanSmooth As Integer
    Dim tTropSmooth As Integer
    Dim tStrawSmooth As Integer
    Dim tVanilla As Integer
    Dim tCookie As Integer
    Dim tManShake As Integer
    Dim tBanShake As Integer


    tMango = txtMango.Text
    tOrange = txtOrange.Text
    tStrawberry = txtStrawberry.Text
    tWatermelon = txtWatermelon.Text
    tMinty = txtMinty.Text
    tCoke = txtCoke.Text
    tDiet = txtDiet.Text
    tSprite = txtSprite.Text
    tMineral = txtMineral.Text
    tSpark = txtSparkling.Text
    tManSmooth = txtMansmooth.Text
    tBanSmooth = txtBanana.Text
    tTropSmooth = txtTropical.Text
    tStrawSmooth = txtStrawSmooth.Text
    tVanilla = txtVanilla.Text
    tCookie = txtChipCookie.Text
    tManShake = txtManShake.Text
    tBanShake = txtBanShake.Text


    Dim TotalSum As Double = 0
    If Me.chkJuices.Items().ToString = "Mango" Then
        TotalSum += (100 * tMango)
    End If
    If Me.chkJuices.Items().ToString = "Orange" Then
        TotalSum += (100 * tOrange)
    End If
    If Me.chkJuices.Items().ToString = "Strawberry" Then
        TotalSum += (100 * tStrawberry)
    End If
    If Me.chkJuices.Items().ToString = "Watermelonade" Then
        TotalSum += (100 * tWatermelon)
    End If
    If Me.chkJuices.Items().ToString = "Minty Pineade" Then
        TotalSum += (100 * tMinty)
    End If

    txtJuice.Text = TotalSum
End Sub

在单击按钮时,您必须注意选中的复选框,然后进行正确的计算

Private Sub Calculate() Handles Button.click
    Dim TotalSum As Double = 0
    For i = 0 To (CheckedListBox1.Items.Count - 1)
        If CheckedListBox1.GetItemChecked(i) = True Then
            If CheckedListBox1.Items(i).ToString = "Mango" Then
                TotalSum += (100 * tMango)
            End If

            If CheckedListBox1.Items(i).ToString = "Orange" Then
                TotalSum += (100 * tOrange)
            End If
        End If
    Next
End Sub