.net 为什么我的价格框记得我以前在里面输入的东西。我不希望这种情况发生。有什么建议吗?

.net 为什么我的价格框记得我以前在里面输入的东西。我不希望这种情况发生。有什么建议吗?,.net,vb.net,.net,Vb.net,为什么我的价格框记得我以前在里面输入的东西。我不希望这种情况发生。有什么建议吗? 这是我的密码。有人知道如何防止这种情况发生吗。第二次我在pricebox中输入价格时,它会记住以前的金额 Private Sub ProductIDComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboProductIDLookup.SelectedIndexCha

为什么我的价格框记得我以前在里面输入的东西。我不希望这种情况发生。有什么建议吗? 这是我的密码。有人知道如何防止这种情况发生吗。第二次我在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
Private Sub-ProductIDComboBox\u SelectedIndexChanged(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理CBOPProductidLookup.SelectedIndexChanged
'测试以确定是否已选择产品
如果cboProductIDLookup.SelectedIndex-1,则
'将selectedIndex存储到变量
Dim RowInteger As Integer=cboProductIDLookup.SelectedIndex
'基于RowInteger,将值显示到文本框控件
'来自名为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”)
如果结束
'txtQuantityAmount.Focus()
txtPriceAmount.Focus()
txtPriceAmount.Clear()
端接头
私有子txtPriceAmount_KeyPress(ByVal sender作为对象,ByVal e作为System.Windows.Forms.KeyPressEventArgs)处理txtPriceAmount.KeyPress
检查KeyDown事件中设置的标志。
如果acceptableKey=False,则
停止将字符输入控件,因为它不是数字。
e、 已处理=真
返回
其他的
“必须在第一个位置”
如果e.KeyChar=Convert.ToChar(Keys.Back),则
如果strCurrency.Length>0,则
strCurrency=strCurrency.Substring(0,strCurrency.Length-1)
如果结束
其他的
strCurrency=strCurrency&e.KeyChar
如果结束
如果strCurrency.Length=0,则
txtPriceAmount.Text=“”
ElseIf strCurrency.Length=1,则
txtPriceAmount.Text=“0.0”和strCurrency
如果strCurrency.Length=2,则
txtPriceAmount.Text=“0.”&strCurrency
如果strucurrency.Length>2,则
txtPriceAmount.Text=strCurrency.Substring(0,strCurrency.Length-2)&“&&strCurrency.Substring(strCurrency.Length-2)
如果结束
txtPriceAmount.Select(txtPriceAmount.Text.Length,0)
如果结束
e、 已处理=真
端接头
私有子PurchaseToolStripMenuItem\u单击(ByVal发送者作为System.Object,ByVal e作为System.EventArgs)处理PurchaseToolStripMenuItem。单击
'确定是否找到产品的测试。
如果txtDescription.Text=String.Empty,则
'无法购买,找不到产品
MessageBox.Show(“购买前必须选择有效的产品。”,“无法购买”,MessageBoxButtons.OK,MessageBoxIcon.叹号)
txtProductID.Focus()
txtProductID.SelectAll()
其他的
“你可以购买该产品吗
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,”)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'累计此客户订单的总价值
'并将其显示到输出框中
TotalDueDecimal+=(txtPriceAmount.Text.ToString*txtQuantityAmount.Text)
txtTotalDueAmount.Text=TotalDueDecimal.ToString(“C2”)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'按产品将总销售额累积到阵列中
Dim IndexInteger As Integer=cboProductIDLookup.SelectedIndex
ProductSalesTotalDecimal(IndexInteger)+=(txtPriceAmount.Text*txtQuantityAmount.Text)
“在这里,你可以清除产品信息的形式,如果你认为
“这是一个很好的处理方法
cboProductIDLookup.SelectedIndex=-1
txtProductID.Clear()
txtDescription.Clear()
txtPriceAmount.Clear()
txtQuantityAmount.Clear()
txtProductID.Focus()
如果结束
端接头

这通常会发生在ASP.NET/web应用程序中(并且可以关闭),但是您的应用程序是winforms应用程序,因此不应该发生这种情况,除非您的系统中安装了一些第三方组件为您执行此操作。您需要关闭该组件

现在,您没有指定它发生的位置。如果是下拉列表,则是,它将自动完成(Windows/IE设置的一部分)。如果它是一个文本框,那么就没什么可解释的了

要为dropdownlist关闭它,请在设计器中将AutoCompleteMode设置为“无”。如果有自定义源被绑定到文本框,则同样适用于文本框

这看起来也很有趣:

 txtPriceAmount.Text = InventoryProduct(RowInteger).PriceDecimal.ToString("C2")

这也可能是问题所在,可能代码中的RowInteger没有正确更新,因此您认为它记住了以前的输入,但实际上它只是错误的索引。

按键事件中的代码很可能是错误的。把程序记下来,看看它是否消失了

由于
strCurrency
未在该过程中声明,因此它必须具有更大的
范围
,因此它会“记住”上次的内容(特别是因为您没有在该过程中初始化它)

规则#32==代码越少越好

规则32a==几乎在任何时候跟踪用户的击键,您都是这样
ProductSalesTotalDecimal(IndexInteger) += _
       (txtPriceAmount.Text * txtQuantityAmount.Text)