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

问题描述 投票:-1回答:1

我已经制作了一个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
vb.net-2010
1个回答
0
投票

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

enter image description here

第8行应该从第4行恢复到第1行吗?或者第8行是错字?

第10行尝试了什么?预期结果是什么?只是说“它不再起作用”尚不清楚。

© www.soinside.com 2019 - 2024. All rights reserved.