• We just launched and are currently in beta. Join us as we build and grow the community.

How to Cancel Delete in BindingNavigator

Gor510

Eccentric Innovator
G Rep
0
0
0
Rep
0
G Vouches
0
0
0
Vouches
0
Posts
152
Likes
20
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 400 XP
When you add a DataSet to your Windows Form a BindingNavigator is automatically created with navigation to your record and it also includes Delete and Add button.

When you click the Delete button there is no confirmation if you want to cancel the operation. The solution to this is to set the DeleteItem to None. See screenshot below:

cancel_delete_bindingnavigator_.jpg


Here's the code in the Delete button under BindingNavigator:

  1. Private

    Sub

    BindingNavigatorDeleteItem_Click(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    EventArgs

    )
  2. If

    MessageBox.

    Show

    (

    "Are you sure you want to delete this record?"

    , "Delete record"

    , MessageBoxButtons.

    YesNo

    , MessageBoxIcon.

    Exclamation

    )

    =

    Windows.

    Forms

    .

    DialogResult

    .

    Yes

    Then
  3. Me

    .

    ProgramsBindingSource

    .

    RemoveCurrent

    (

    )

  4. Try
  5. Me

    .

    Validate

    (

    )
  6. Me

    .

    ProgramsBindingSource

    .

    EndEdit

    (

    )
  7. Me

    .

    TableAdapterManager

    .

    UpdateAll

    (

    Me

    .

    ProgramsDataSet

    )

  8. MessageBox.

    Show

    (

    "Record successfully deleted."

    )

  9. Me

    .

    Close

    (

    )
  10. Catch

    ex As

    Exception
  11. MessageBox.

    Show

    (

    ex.

    Message

    , "Error"

    , MessageBoxButtons.

    OK

    , MessageBoxIcon.

    Error

    )
  12. End

    Try
  13. End

    If
  14. End

    Sub

 

452,496

327,515

327,523

Top