从总值中减去已删除的值 [英] Subtracting the deleted value from the total value

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

问题描述

如果您在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

推荐答案

5",其他 AnswerNumber = A * txtDisplay.Text MyItem = ListView1.Items.Add(" & txtDisplay.Text& "
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(答案号码) 结束 如果 结束
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上,您可以获取AnswerNumber的值.
您可以在此处自己进行计算,方法是将AnswerNumberm的值减去lblTotal.Text的值.

-------------------------------------
希望这至少会给您带来火花.
一个大爆炸足以引起火花:)
On the Sub btnRemove_Click , you can get the the value of AnswerNumber.
You can do the calculation here itself by subtracting the Value of AnswerNumberm the value of lblTotal.Text .

-------------------------------------
Hope this will give you at least a spark.
A spark is enough for a big bang :)


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆