我对vb.net和编程非常陌生,所以我希望我能得到一个非常简单的答案。
我写了一个输入框,用于检索用户输入并将其存储在变量salesQty中。
salesQty =
InputBox("Enter the sales quantity for " & itemListBox.Text, "Daily Sales Entry", "0")
之后,我尝试将Listbox的text属性设置为等于salesQty(假设它将更改所选项目的显示文本),但它似乎根本没有变化。
salesQtyListBox.Text = salesQty
这是整个代码:
Private Sub enterSalesQtyButton_Click(sender As Object, e As EventArgs) Handles enterSalesQtyButton.Click
'Retrieve number of items in itemList Box and sets it as variable numItems
Dim numItems As Integer = itemListBox.Items.Count
'Declare index to use as counter
Dim index As Integer
Do While index < numItems
index = index + 1
Dim salesQty As String
salesQty =
InputBox("Enter the sales quantity for " & itemListBox.Text, "Daily Sales Entry", "0")
'Changes Sales Quantity text to the users input that has been stored in SalesQty
salesQtyListBox.Text = salesQty
'Selects next index until all have been selected
If itemListBox.SelectedIndex < numItems - 1 Then
itemListBox.SelectedIndex = itemListBox.SelectedIndex + 1
End If
Loop
enterSalesQtyButton.Enabled = False
applyDailySalesButton.Enabled = True
End Sub
答案 0 :(得分:0)
Private Sub enterSalesQtyButton_Click(sender As Object, e As EventArgs) Handles enterSalesQtyButton.Click
' Declare the varible outside the loop,
' because we dont need a new string every time.
Dim salesQty As String = ""
' Loops through all the items in the list box.
For i As Integer = 0 To itemListBox.Items.Count - 1
' Gets the user quantity for the current item (the "i" item of the list box).
salesQty = InputBox("Enter the sales quantity for " & itemListBox.Items(i), "Daily Sales Entry", "0")
' Changes the "i" item according to the user data.
itemListBox.Items(i) = salesQty
Next
End Sub
答案 1 :(得分:-1)
要将项目添加到列表框,请使用以下代码:
salesQtyListBox.items.add(salesQty)
我不确定这是否完全回答了你的问题,但希望这应该有所帮助。