【发布时间】:2019-02-16 08:06:33
【问题描述】:
Why didn't trigger the CellEndEdit event of DataGridView 这里有一个类似的问题,所以请不要告诉我它已经回答了。 :-) 该解决方案解决了从网格中单击的问题,而不是从行中的最后一个单元格中跳出。
我正在将数据输入到 datagridview 的新行中。当我离开该行时,我会检查该行是否是新的。如果是新行,我将数据添加到数据库中。但是,当我跳出最后一个单元格时,RowLeave 会触发并且该行中的最后一个单元格是空的。其他单元格显示数据,但不显示最后一个。
当跳出最后一个字段时,我验证了 LeaveRow 在 CellEndEdit 之前触发。
如果我在最后一个单元格中输入数据并单击上一个单元格,然后离开该行,它会从最后一个单元格中捕获数据。
如何强制在 RowLeave 事件触发之前保存在最后一个单元格中输入的值?我正在 RowLeave 事件中保存新行。
这是 RowLeave 事件的代码
Private Sub dgVisa_RowLeave(sender As Object, e As DataGridViewCellEventArgs) Handles dgVisa.RowLeave
Dim row As DataGridViewRow = dgVisa.CurrentRow
If dgVisa.IsCurrentRowDirty Then
MsgBox(row.Cells(0).FormattedValue)
MsgBox(row.Cells(1).FormattedValue)
MsgBox(row.Cells(2).FormattedValue)
MsgBox(row.Cells(3).FormattedValue)
MsgBox(row.Cells(4).FormattedValue)
MsgBox(row.Cells(5).FormattedValue)
If gbolUserAddedRow = True Then
Dim AddRecord As New GetMSCADPaymentDetailsTableAdapters.uspMSGetMSCADBankDetailsByCreditCardTypeIdentTableAdapter
AddRecord.Insert(#9/1/2018#,
1,
5,
1,
4)
AddRecord.Insert(CDate(row.Cells(1).FormattedValue),
1,
CDbl(row.Cells(3).FormattedValue),
CDbl(row.Cells(4).FormattedValue),
CDbl(row.Cells(5).FormattedValue))
gbolUserAddedRow = False
End If
End If
End Sub
【问题讨论】:
标签: vb.net datagridview datarow