从ListBox中删除项目并更新Total Visual Basic

时间:2015-07-23 19:14:51

标签: vb.net button visual-studio-2012 listbox

我是VB的新手,我已设法在列表框中添加项目并更新总计,因为我一直在添加项目。 我的问题是 我想从ListBox中删除所选项目并更新Total / Deduct价格,但我不知道该怎么做。我发布了一个示例代码,用于添加总数。

Private Sub btncoffee6_Click(sender As Object, e As EventArgs) Handles btncoffee6.Click
        Dim sum As Double
        sum = 1.5
        itembox.Items.Add("Regular Coffee       $1.00")
        For x As Integer = 0 To itembox.Items.Count - 1
            sum += Val(itembox.Items.Item(x).ToString)
        Next
        txttotal.Text = sum.ToString
        itembox.Items.Add(sum)
    End Sub

1 个答案:

答案 0 :(得分:0)

尝试removeAt(),然后获得一些教程

Dim sum as Double
Private Sub btnRemove_Click(sender As Object, e As EventArgs) Handles btnRemove.Click
    itembox.Items.RemoveAt(itembox.SelectedIndex)
    sum = sum - Val(itembox.Items.Item(itembox.SelectedIndex).ToString)        
    txttotal.Text = sum.ToString
    itembox.Items.Add(sum)
End Sub