DataGridViewTextBoxColumn是否有文本更改事件处理程序?

时间:2016-08-27 17:31:14

标签: c# datagridview

我的datagridview需要帮助 除了数量列之外,所有列都是只读的。用户可以输入任何数量值并自动将结果(价格*数量)显示给小计列

Click here to see example

1 个答案:

答案 0 :(得分:0)

也许这已经很晚了,但请尝试将其添加到您的代码中:

Private Sub dg1_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles dg1.CellValueChanged
    Try
        dg1.CommitEdit(DataGridViewDataErrorContexts.Commit)
        If e.ColumnIndex = 9 Then 'columindex for your QUANTITY. 9 is just a sample
            dg1.CommitEdit(DataGridViewDataErrorContexts.Commit)
            dg1.CurrentRow.Cells("SubTotal").Value = (VAL(dgSalesOrderLine.CurrentRow.Cells("SalesOrderAmount").Value) * VAL(dgSalesOrderLine.CurrentRow.Cells("SalesOrderQuantity").Value))
        End If
    Catch ex As Exception
    End Try
End Sub


Private Sub dg1_CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles dg1.CurrentCellDirtyStateChanged
    dg1.CommitEdit(DataGridViewDataErrorContexts.Commit)
End Sub