dcsimg
Results 1 to 3 of 3

Thread: Edit before changing records

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2009
    Location
    Oklahoma, USA
    Posts
    62

    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.

    Name:  Untitled.png
Views: 142
Size:  22.6 KB
    Last edited by wjburke2; Jul 29th, 2019 at 09:10 AM.

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,169

    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

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2009
    Location
    Oklahoma, USA
    Posts
    62

    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width