0

现在,我在离开 EventArgs 中使用 EndEdit,但是当我使用 EndEdit 时,我无法关闭我的表单。有谁知道原因?

以下是我的休假功能:

 Private Sub dgv_Leave(ByVal sender As System.Object, 
                       ByVal e As System.EventArgs) Handles dgv.Leave
            Me.dgv.EndEdit()
    End Sub
4

2 回答 2

1

这可能是由于 DataGridView 中可能存在一些验证错误。您必须检查是否dataGridView.EndEdit()成功,并且您可能还需要检查您的 Cell 和 RowValidating 事件(如果存在)。

于 2013-06-05T07:59:15.837 回答
0

我找到了解决 EndEdit 问题的解决方案。然后,我可以正确结束编辑,并且可以成功关闭我的表单。

http://dobon.net/vb/bbs/log3-35/21499.html

Public Class Form4_4
    Inherits Form

    Dim WithEvents m_dgv As New DataGridView()
    Dim WithEvents m_editingcontrol As Control

    Private Sub Form4_4_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        m_dgv.Dock = DockStyle.Fill
        m_dgv.RowCount = 10
        m_dgv.ColumnCount = 3
        Me.Controls.Add(m_dgv)
    End Sub

    Private Sub m_dgv1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles m_dgv.CellEndEdit
        Me.m_editingcontrol = Nothing ' ← Cancel EventHandler Here
        Console.WriteLine("CellEndEdit")
    End Sub

    Private Sub m_dgv_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles m_dgv.EditingControlShowing
        Console.WriteLine("EditingControlShowing")
        Me.m_editingcontrol = e.Control ' ← Register EventHandler Here
    End Sub

    Private Sub m_editingcontrol_PreviewKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles m_editingcontrol.PreviewKeyDown
        If e.KeyCode = Keys.Return Then
            Me.m_dgv.EndEdit()
        End If
    End Sub
End Class
于 2013-06-05T09:45:27.997 回答