2016-06-11 72 views
0

我想要做的是我將項目添加到列表框中的文本框將自動更新。這我已經做了我可以添加的價格將被添加,但只爲數量1,如果我添加1個項目超過1個數量將只計爲數量1項目價格如何解決?如何更新列表框中的文本框總價格

enter image description here

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 

更新

這仍然無法修復

回答

1

你在For - Next loop

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 
+0

使用price代替caculate不能和我有更新我的代碼,但仍然沒有工作 – Chew

+0

查看更新的答案。但是,如果仍然存在問題,您必須更具體:什麼「不起作用」?是否引發任何錯誤?如果是,在哪一行以及哪一種? – user3598756

+0

thx它的工作!在我遇到的問題之前,我添加的項目多個只會+第一個項目的價格。 – Chew