Loading

How to Cancel Delete in BindingNavigator

Submitted by: 
Visitors have accessed this post 20749 times.


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:

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.  
  5. Try
  6. Me.Validate()
  7. Me.ProgramsBindingSource.EndEdit()
  8. Me.TableAdapterManager.UpdateAll(Me.ProgramsDataSet)
  9.  
  10. MessageBox.Show("Record successfully deleted.")
  11.  
  12. Me.Close()
  13. Catch ex As Exception
  14. MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  15. End Try
  16. End If
  17. End Sub



Add new comment

(If you're a human, don't change the following field)
Your first name.
(If you're a human, don't change the following field)
Your first name.
(If you're a human, don't change the following field)
Your first name.

Filtered HTML

  • You may insert videos with [video:URL]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.