简体   繁体   English

vb.net keyup事件

[英]vb.net keyup event

I have a datagridview having 3 columns (qty,scraft factor,actuall qty). 我有一个datagridview有3列(数量,工艺因素,精算数量)。 What I want is if the user encode 50 in qty and 2 in scraf factor, actuall qty will automatically computed based on qty multiply by 2. I was using keyup event. 我想要的是,如果用户以数量为单位编码50,以scraf因子编码为2,则实际数量将基于数量乘以2自动计算。我正在使用keyup事件。 Now I am using endedit to get the current value of the current row and column, now the problem is if the amount to be encoded is more than one digit it will not accept because of endedit. 现在,我正在使用endedit获取当前行和列的当前值,现在的问题是,如果要编码的数量超过一位,则由于endedit将不被接受。 What event do I have to used? 我必须使用什么活动? or any solution with this scenario. 或这种情况下的任何解决方案。 Please see the code below 请看下面的代码

thanks in advance. 提前致谢。

tirso 提尔索

Private Sub tbx_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
    dgvIngredient.EndEdit()

    Dim intCurrentRow As Integer = dgvIngredient.CurrentRow.Index
    Dim decQuantity As Decimal
    Dim decScrafFactor As Decimal
    Dim decActuallQty As Decimal

    decQuantity = dgvIngredient.Item(2, intCurrentRow).Value
    decScrafFactor = dgvIngredient.Item(3, intCurrentRow).Value
    decActuallQty = decQuantity * decScrafFactor

    dgvIngredient.Item(4, intCurrentRow).Value = decActuallQty

End Sub

For me it works without problems in the CellEndEdit event. 对我来说,它在CellEndEdit事件中可以正常工作。

Try this (all in 1 step): 尝试一下(全部一步):

dgvIngredient.Rows(e.RowIndex).Cells(4).Value = Convert.ToDecimal(dgvIngredient.Rows(e.RowIndex).Cells(2).Value) * Convert.ToDecimal(dgvIngredient.Rows(e.RowIndex).Cells(3).Value)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM