Here is my DataGridView:
Me.DGV_InvoiceContainers.MultiSelect = False
Me.DGV_InvoiceContainers.ReadOnly = True
Me.DGV_InvoiceContainers.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect
...
It contains one column and multiple rows. When clicking on a cell/row (different from the selected one), a logic test is done (under MouseDown Event handler) to be sure all conditions are fulfilled before changing selection. If not, SelectionChanged event may not be raised/handled, nothing may happen (Like when clicking on a Cancel button).
Is it possible?
Solved:
Private Sub DGV_InvoiceContainers_RowValidating(sender As Object, e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles DGV_InvoiceContainers.RowValidating
If Me.CurrentInvoice.IsOpen Then
If Me.CurrentInvoice.ChangesHaveBeenMade Then
Dim dialogResult As New DialogResult
dialogResult = MessageBoxA.Show("Do you want to save changes?", "Question", _
MessageBoxAAutoFill.Title, _
MessageBoxAButtons.YesNoCancel, Library.MessageBoxAMode.Question, MessageBoxAButtonsAlignment.Right, _
MessageBoxA.DialogResultButtons.Button1, {"&Save", "Do ¬ save", "&Cancel"})
Select Case dialogResult
Case Windows.Forms.DialogResult.Yes
Me.Reader.Close()
Me.SaveChanges()
Me.InvoiceContainerSelectionAllowed = True
Case Windows.Forms.DialogResult.No
Me.Reader.Close()
Me.InvoiceContainerSelectionAllowed = True
Case Else
Me.InvoiceContainerSelectionAllowed = False
End Select
Else
Me.Reader.Close()
Me.InvoiceContainerSelectionAllowed = True
End If
'
If Me.InvoiceContainerSelectionAllowed Then
Me.DisposeInvoiceData()
End If
Else
Me.InvoiceContainerSelectionAllowed = True
End If
If Not Me.InvoiceContainerSelectionAllowed Then
e.Cancel = True
Return
End If
End Sub