为什么我的价格框记得我之前输入的内容。我不希望这种情况发生。有什么建议么?这是我的代码。有谁知道如何防止这种情况发生。我第二次在 pricebox 中输入价格时,它会记住之前的金额。
Private Sub ProductIDComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboProductIDLookup.SelectedIndexChanged
'Test to determine if a product has been selected
If cboProductIDLookup.SelectedIndex <> -1 Then
'Store the selectedIndex to variable
Dim RowInteger As Integer = cboProductIDLookup.SelectedIndex
'Based on RowInteger, display values to TextBox controls
'from the array named inventoryProduct
txtProductID.Text = InventoryProduct(RowInteger).ProductIDString
txtDescription.Text = InventoryProduct(RowInteger).DescriptionString
txtQuantityAmount.Text = InventoryProduct(RowInteger).QuantityInteger.ToString("N0")
txtPriceAmount.Text = InventoryProduct(RowInteger).PriceDecimal.ToString("C2")
End If
' txtQuantityAmount.Focus()
txtPriceAmount.Focus()
txtPriceAmount.Clear()
End Sub
Private Sub txtPriceAmount_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPriceAmount.KeyPress
'''''''' Check for the flag being set in the KeyDown event.
If acceptableKey = False Then
'''''''' Stop the character from being entered into the control since it is non-numerical.
e.Handled = True
Return
Else
'''''''' 'must be in first position
If e.KeyChar = Convert.ToChar(Keys.Back) Then
If strCurrency.Length > 0 Then
strCurrency = strCurrency.Substring(0, strCurrency.Length - 1)
End If
Else
strCurrency = strCurrency & e.KeyChar
End If
If strCurrency.Length = 0 Then
txtPriceAmount.Text = ""
ElseIf strCurrency.Length = 1 Then
txtPriceAmount.Text = "0.0" & strCurrency
ElseIf strCurrency.Length = 2 Then
txtPriceAmount.Text = "0." & strCurrency
ElseIf strCurrency.Length > 2 Then
txtPriceAmount.Text = strCurrency.Substring(0, strCurrency.Length - 2) & "." & strCurrency.Substring(strCurrency.Length - 2)
End If
txtPriceAmount.Select(txtPriceAmount.Text.Length, 0)
End If
e.Handled = True
End Sub
Private Sub PurchaseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PurchaseToolStripMenuItem.Click
'Test to determine if a product was found.
If txtDescription.Text = String.Empty Then
'Cannot purchase, product was not found
MessageBox.Show("You must select a valid product before purchasing.", "Cannot Purchase", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtProductID.Focus()
txtProductID.SelectAll()
Else
'Can purchase the product
Dim ProductString As String = txtProductID.Text.PadRight(12, " ") & "" & txtDescription.Text.PadRight(50, " ") & "" & txtQuantityAmount.Text.PadRight(7, " ") & "" & txtPriceAmount.Text.PadLeft(9, " ").ToString
lstPurchaseItems.Items.Add(ProductString)
' Double.Parse(txtPriceAmount.Text).ToString("C2").PadLeft(9, " ")
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Accumulate the total value of this customer order
'and display it to the output box
TotalDueDecimal += (txtPriceAmount.Text.ToString * txtQuantityAmount.Text)
txtTotalDueAmount.Text = TotalDueDecimal.ToString("C2")
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Accumulate total sales by product to an array
Dim IndexInteger As Integer = cboProductIDLookup.SelectedIndex
ProductSalesTotalDecimal(IndexInteger) += (txtPriceAmount.Text * txtQuantityAmount.Text)
'Here you can clear the form of product info if you think
'that is a good way to do the processing
cboProductIDLookup.SelectedIndex = -1
txtProductID.Clear()
txtDescription.Clear()
txtPriceAmount.Clear()
txtQuantityAmount.Clear()
txtProductID.Focus()
End If
End Sub