本文介绍了从总值中减去已删除的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您在ListView中有一个项目列表,这些项目的总计显示在Label(lblDisplay.Text)中,并且您删除了其中一个值,那么当您单击删除"时,如何自动从总计中减去已删除的值项目按钮(btnRemove)?
代码:

If you have a list of items in a ListView which have their total displayed in a Label (lblDisplay.Text) and you delete one of the values, how can you subtract the deleted value from the total automatically when you click the Remove Item button (btnRemove)?
The Code:

Private Sub Apple_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Apple.Click
Dim MyItem As ListViewItem
Dim A As Single = 5
        If txtDisplay.Text = "" Then 'txtDisplay is a textbox where I put number of items the customer is purchasing.
            MyItem = ListView1.Items.Add("Apple 1 @ $5", 0)
            MyItem.SubItems.Add(A)
            lblTotal.Text = Val(lblTotal.Text) + Val(A)
        Else
            AnswerNumber = A * txtDisplay.Text
           MyItem = ListView1.Items.Add("Apple " & txtDisplay.Text & " @ $5", 0)
           MyItem.SubItems.Add(AnswerNumber)
            lblTotal.Text = Val(lblTotal.Text) + Val(AnswerNumber)
        End If
End Sub



这是删除项目的代码:
私有Sub btnRemove_Click(ByVal发送者为System.Object,ByVal e为System.EventArgs)处理btnRemove.Click
ListView1.Items.Remove(ListView1.SelectedItems.Item(index:= 0))
结束Sub



This is the Code to Remove Item:
Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
ListView1.Items.Remove(ListView1.SelectedItems.Item(index:=0))
End Sub

推荐答案




这是删除代码:
私有Sub btnRemove_Click(ByVal发送者为System.Object,ByVal e为System.EventArgs)处理btnRemove.Click
ListView1.Items.Remove(ListView1.SelectedItems.Item(index:= 0))
结束Sub



This is the Code to Remove Item:
Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
ListView1.Items.Remove(ListView1.SelectedItems.Item(index:=0))
End Sub



这篇关于从总值中减去已删除的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 02:28