【问题标题】:Listview vb.net列表视图 vb.net
【发布时间】:2013-02-17 11:40:00
【问题描述】:

我的表单中有一个列表视图。每次用户输入项目代码时,它都会在列表视图中列出。我要做的是当用户输入现金时,系统计算出找零后,我想在数据库记录中扣除购买的物品。截至目前,我有这个代码:

    Do While tmp <= ListView1.Items.Count

        Do While a <= ds.Tables("ItemInfo").Rows.Count               

            it = ListView1.Items(tmp - 1).SubItems(0).Text
            qt = ListView1.Items(tmp - 1).SubItems(3).Text


            If it = ds.Tables("ItemInfo").Rows(a).Item("ItemCode") Then
                'MsgBox(ds.Tables("ItemInfo").Rows(a).Item("ItemCode"))
                ct = ds.Tables("ItemInfo").Rows(a).Item("Qty")
                nw = Convert.ToInt32(ct) - Convert.ToInt32(qt)
                MsgBox(nw)
                con1.Open()
                mycommand = New SqlCommand("update ItemInfo set Qty='" & nw & "' where ItemCode='" & it & "'", con1)
                mycommand.ExecuteNonQuery()
                con1.Close()

                'Exit Do

                'Else


            End If
            a = a + 1
        Loop

        tmp = tmp + 1

    Loop

但问题是它没有扣除列表视图中的所有项目。它始终是列表视图中的第一行,谁在数据库中被扣除。我不知道问题是在循环还是什么。提前谢谢你:)

【问题讨论】:

  • 欢迎来到 stackOverFlow,FAQ 必读
  • 如何循环遍历所有列表视图项?因为在我的代码中,它总是被读取的 listview 的第一行..

标签: vb.net listview


【解决方案1】:

您可以使用foreach 读取ListView 中的所有项目

For Each i As ListViewItem In listView1.Items

Next

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-19
    • 1970-01-01
    • 2014-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多