The following sources in Microsoft Visual Basic 2015 are not working, is there anything wrong (missing)?
Private SubDataGridView_Leave (sender As Object, eAs EventArgs) Handles DataGridView.Leave
Dimdgv As DataGridView= DirectCast (sender, DataGridView)
If dgv.IsCurrentCellInEditMode Then
dgv.CurrentCell= Nothing
End If
Me. Close()
End Sub
Supplemental:
If it is not in the edit state (F2 press), the form closes when the focus leaves DataGridView.
I haven't found a perfect solution yet, but I think I can do the following.
Private Sub Me_FormClosing (sender As Object, eAs FormClosingEventArgs) Hands MyBase.FormClosing
If ForceToCloseForm Then
e.Cancel=False
End If
End Sub
Private Sub DataGridView_Leave (sender As Object, eAs EventArgs) Handles DataGridView.Leave
Dimdgv As DataGridView= DirectCast (sender, DataGridView)
If dgv.IsCurrentCellInEditMode Then
dgv.CurrentCell= Nothing
ForceToCloseForm=True
End If
Me. Close()
End Sub
© 2024 OneMinuteCode. All rights reserved.