首页 > 解决方案 > Visual basic ListView:如何在第一行禁用自动选择?

问题描述

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

程序删除订单数量添加更多项目此处出现错误

    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

解决方案


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

在此处输入图像描述

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

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


推荐阅读