【问题标题】:how to update my textbox total price which is in listbox如何更新列表框中的文本框总价
【发布时间】:2016-06-12 00:22:16
【问题描述】:

我想要做的是将项目添加到列表框中,文本框将自动更新。我已经完成了我可以添加的价格将被添加但仅适用于数量 1 如果我添加 1 件超过 1 个数量将仅计为数量 1 件价格如何解决?

count = Math.Round(qty_of_item, 2) * (product_price)

        lblprice.Text = (" Rm " & count)
        ListBox1.Items.Add(product_name)

        ListBox4.Items.Add(product_class)
        ListBox5.Items.Add(product_size)

        ListBox3.Items.Add((" " & Math.Round(qty_of_item)))
        ListBox2.Items.Add(FormatCurrency(count))

        caculate = count

        total = 0

        Dim price As Decimal = 0
        price = total + caculate

        For i As Integer = 0 To ListBox2.Items.Count - 1 'get the item count inside listview
            price = (CDec(ListBox2.Items(0).ToString())) 'get the value of item of each item in each listbox row
            total += price 'add price into total
        Next

        txtsubtotal.Text = FormatCurrency(total)

        gst = total * 0.06
        txtgst.Text = FormatCurrency(gst)

        total_after_gst = total + gst
        txtfinaltotal.Text = FormatCurrency(total_after_gst)

    Else
        MessageBox.Show("Qty value cant be empty And only allow Integer", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error)

    End If

更新

这个还是解决不了

【问题讨论】:

    标签: visual-studio-2015 textbox listbox


    【解决方案1】:

    您必须在 For - Next loop 中使用 price 代替 caculate

    For i As Integer = 0 To ListBox2.Items.Count - 1 'get the item count inside listview
        price = CDec(ListBox2.Items(i)) 'get the value of item of each item in each listbox row
        total += price 'add price into total
    Next
    

    【讨论】:

    • 不能,我已经更新了我的代码,但仍然没有工作
    • 查看更新的答案。但是如果仍然存在问题,您必须更具体:什么“不起作用”?是否抛出任何错误?如果是,在哪一行和哪一种?
    • 谢谢它的工作!之前我面临的问题是当我添加项目时,倍数只会+第一个项目的价格。
    猜你喜欢
    • 2014-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多