Visual Basic ListView:如何在第一行中禁用自动选择?

时间:2019-03-03 03:48:45

标签: vb.net-2010

我已经做出了一个listview命令,我按下一个按钮,该项目就会自动出现在listview中。 listview有3列:订单列表,价格列表和数量。我添加了一个按钮,该按钮可根据其信息删除数量并降低价格。我已成功地通过选择特定数量移除了该数量,并且该特定数量仅适用于一项,但是无论何时添加更多项,它都不再起作用。预先感谢您的帮助!

The programRemoving the quantity of the orderMore items addedThe 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

1 个答案:

答案 0 :(得分:0)

我很难按照这些步骤进行操作,并确定问题与期望的结果(从未说明)。这就是我所看到的序列

enter image description here

第8行是否应该从第4行恢复为第1行?还是第8行是错字?

第10行尝试了什么?预期的结果是什么?只是说“它不再有用”了。