【问题标题】:In datagridview (vb.net) the RowLeave fires before the CellEndEdit in the last cell of the row在 datagridview (vb.net) 中,RowLeave 在行的最后一个单元格中的 CellEndEdit 之前触发
【发布时间】: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


    【解决方案1】:

    我不知道这是否只是一种解决方法,但我确实从解决问题的另一个问题中找到了一些东西。

    我将 dgVisa.EndEdit() 放在上面显示的代码的开头。它强制 EndCellEdit 在其余代码之前触发。

    如果有人有更优雅的答案,请告诉我。

    谢谢! 乔

    【讨论】:

    • 我正要发这个,但你想通了。 If dgVisa.IsCurrentCellInEditMode Then dgVisa.EndEdit()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多