How to cancel procedures having an Argument e As System.EventArgs

How does one cancel a procedure having the Argument "e As System.EventArgs"?

In the below example, the e.Cancel line of code gives the error:  'Cancel' is not a member of 'system.EventArgs".  What is the proper way to do this?


Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        If MsgBox("Delete?", MsgBoxStyle.YesNo) = MsgBoxResult.No Then
            e.Cancel = True
        End If
    End Sub

Open in new window

KentDBerryAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

indianguru2Commented:

Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        If MsgBox("Delete?", MsgBoxStyle.YesNo) = MsgBoxResult.No Then
            e.Handled= True
        End If
    End Sub

Open in new window

0
KentDBerryAuthor Commented:
e.Handled = True gives the same error message as e.Cancel = True
0
Éric MoreauSenior .Net ConsultantCommented:
You don't need to cancel the event, just don't do anything in your condition:

Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        If MsgBox("Delete?", MsgBoxStyle.YesNo) = MsgBoxResult.No Then
            'e.Cancel = True
            'Don't do anything here
        Else
             'Do whatever you want here!
        End If
End Sub
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

KentDBerryAuthor Commented:
Notice that the event is bound to the Delete button on a BindingNavigator, So I have to force the event to cancel or it will delete anyway.
0
KentDBerryAuthor Commented:
I know I could do the suggested way if I create my own button and control the delete process from there.  But I am trying to learn how to control the BindingNavigator Delete or Add process.  
0
KentDBerryAuthor Commented:
Found solution in another question:

I set the property "DeleteItem" On the BindingNavigator to "(none).

Then the below code behind will allow the controlling of the delete process.

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        If MsgBox("Delete?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
            Me.TblExcelSheetsBindingSource.RemoveCurrent()
            Me.TblExcelSheetsBindingSource.EndEdit()
        End If
    End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.