1 Attachment(s)
Edit before changing records
I know this is a old question so if you have seen the answer, just direct me to it. I have a form with a Datagridview for moving between records. I have a routine that checks to see if the user has made any unsaved changes. I ask them if they would like to save changes before leaving the current record. In the event they say yes and the validation fails how do I keep them on the current record so they can fix the errors before the record goes to whichever record they have selected from the data grid view. Basically cancel the move and let them fix the errors or cancel the update before changing records.
Attachment 170099
Re: Edit before changing records
If you want the ability to cancel exiting a row then the RowValidating event would work well.
Code:
Private Sub DataGridView1_RowValidating(sender As Object, e As DataGridViewCellCancelEventArgs) Handles DataGridView1.RowValidating
If MessageBox.Show("Save Changes?", "Save", MessageBoxButtons.YesNo) = DialogResult.No Then
e.Cancel = True
End If
End Sub
Re: Edit before changing records
Thank you, Wes that worked. Don't know why I thought putting the code in the dgv RowLeave would work. Thanks again