我已经做出了一个listview命令,我按下一个按钮,该项目就会自动出现在listview中。 listview有3列:订单列表,价格列表和数量。我添加了一个按钮,该按钮可根据其信息删除数量并降低价格。我已成功地通过选择特定数量移除了该数量,并且该特定数量仅适用于一项,但是无论何时添加更多项,它都不再起作用。预先感谢您的帮助!
The program:Removing the quantity of the order:More items added:The error occurs here
Private Sub Button15_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
If olqlistview.SelectedItems.Count = 0 Then
Beep()
MessageBox.Show("Please select an item.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
Dim totale As Integer, pt As Integer, tp As Integer
Dim x As Integer = olqlistview.SelectedItems.Item(0).SubItems(2).Text, y As Integer = olqlistview.SelectedItems.Item(1).SubItems(1).Text
For i = 0 To olqlistview.SelectedItems.Count
If i = 1 Then
Dim lve As New ListViewItem
totale = Val(olqlistview.SelectedItems.Item(0).SubItems(2).Text) - 1
olqlistview.Items(0).SubItems(2).Text = CStr(totale)
tp = Val(y) / Val(x)
pt = Val(y) - Val(tp)
olqlistview.SelectedItems.Item(0).SubItems(1).Text = Val(pt)
End If
If x = 1 And i = 1 Then
olqlistview.Items.Remove(olqlistview.SelectedItems(0))
End If
Next
Dim lv As ListViewItem
Dim total As Long
Dim quantitytotal As Long
For Each lv In olqlistview.Items
total = total + CStr(lv.SubItems(1).Text)
quantitytotal = quantitytotal + CStr(lv.SubItems(2).Text)
Next
amtdue.Text = total
Label1.Text = total
tq.Text = quantitytotal
End If
End Sub
If olqlistview.SelectedItems.Count = 0 Then
Beep()
MessageBox.Show("Please select an item.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
Dim totale As Integer, pt As Integer, tp As Integer
Dim x As Integer = olqlistview.SelectedItems.Item(0).SubItems(2).Text, y As Integer = olqlistview.SelectedItems.Item(1).SubItems(1).Text
For i = 0 To olqlistview.SelectedItems.Count
If i = 1 Then
Dim lve As New ListViewItem
totale = Val(olqlistview.SelectedItems.Item(0).SubItems(2).Text) - 1
olqlistview.Items(0).SubItems(2).Text = CStr(totale)
tp = Val(y) / Val(x)
pt = Val(y) - Val(tp)
olqlistview.SelectedItems.Item(0).SubItems(1).Text = Val(pt)
End If
If x = 1 And i = 1 Then
olqlistview.Items.Remove(olqlistview.SelectedItems(0))
End If
Next
Dim lv As ListViewItem
Dim total As Long
Dim quantitytotal As Long
For Each lv In olqlistview.Items
total = total + CStr(lv.SubItems(1).Text)
quantitytotal = quantitytotal + CStr(lv.SubItems(2).Text)
Next
amtdue.Text = total
Label1.Text = total
tq.Text = quantitytotal
End If
End Sub