• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2072
  • Last Modified:

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

0
KentDBerry
Asked:
KentDBerry
  • 4
1 Solution
 
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
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
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

Featured Post

Get expert help—faster!

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

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now