Results 1 to 9 of 9

Thread: [RESOLVED] Cancel selection changed in datagridview

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2010
    Posts
    54

    Resolved [RESOLVED] Cancel selection changed in datagridview

    Hi all,

    Ive got a datagridview, which the user can put in to 'edit' mode by double clicking. If they then make changes but click to another row, I want to msg asking if they are sure they want to discard then changes. If they say No I want to stop the selection change from being made.

    Code:
        Private Sub DataGridView1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
            If edit = True Then
                Dim result As String = MsgBox("Are you sure you want to discard your changes?", MsgBoxStyle.YesNo)
                If result = vbYes Then
                    clearedit()
                Else
                    'Here is where I need to cancel the selection change
                End If
            Else
                clearedit()
            End If

  2. #2
    Hyperactive Member
    Join Date
    Jan 2010
    Posts
    285

    Re: Cancel selection changed in datagridview

    I dont understand.

    You wanna your datagridview pass to read only again??
    It helps? So Rate it

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2010
    Posts
    54

    Re: Cancel selection changed in datagridview

    No, maybe I confused you by saying edit mode... ignore that!

    How do I go back to the previous selected row on the selection changed event.

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2010
    Posts
    54

    Re: Cancel selection changed in datagridview

    Anyone?

  5. #5
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Cancel selection changed in datagridview

    Store the row number then restore it:
    Code:
    grdComplete.Rows(intRow).Selected = True
    grdComplete = DataGridView
    intRow = index of the row that was being edited.
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 2010
    Posts
    54

    Re: Cancel selection changed in datagridview

    Ahhh! thanks

  7. #7

    Thread Starter
    Member
    Join Date
    Aug 2010
    Posts
    54

    Re: Cancel selection changed in datagridview

    Cant give you rep again MarMan

  8. #8
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: [RESOLVED] Cancel selection changed in datagridview

    That's OK. The appreciation is appreciated.
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  9. #9

    Thread Starter
    Member
    Join Date
    Aug 2010
    Posts
    54

    Re: [RESOLVED] Cancel selection changed in datagridview

    Just took a different way of thinking about it. Silly me! Thanks for the help

Posting Permissions

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



Click Here to Expand Forum to Full Width