Prevent 'RemoveCurrent' after BindingNavigator DeleteItem Click

After the user clicks the DeleteButton in the binding Navigator, I want to make sure he really wants to delete. ('Are you sure ....'). If he declines, I want to prevent the automatically following RemoveCurrent on the active DataRow. How can I do that



Answer this question

Prevent 'RemoveCurrent' after BindingNavigator DeleteItem Click

  • ChrisMentioned

    Another method that doesn't require changing the system-generated code is simply to delete the default DeleteButton and add a new button from the dropdown list. No method code is generated. You add a delete icon and create  _Click method with your confimation message and delete logic.
  • Chris Doherty

    BunnyStrider wrote:

    No database changes would be made until you did

    MyTableAdapter.Update(myDataTable)

    ...you're just removing the current record from your local data cache, you'd have to update to commit changes...

    ...of course I'm replying to your post a year later so this is probably useless to you...

    But it was HIGHLY valuable to me!! Thanks for completing the circle in this thread.

    Here's my code:

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click

    If (Me.Validate() And Not (SessionsBindingSource Is Nothing)) Then

    Dim msg As String = "WARNING: This action will permanently delete this Session!" & Environment.NewLine & Environment.NewLine & _

    "This record and its related Trial records will be deleted" & Environment.NewLine & _

    "from the database. You cannot undo this action." & _

    Environment.NewLine & Environment.NewLine & Space(10) & "Do you want to delete this Session "

    If (MsgBox(msg, MsgBoxStyle.Exclamation + MsgBoxStyle.OkCancel + MsgBoxStyle.DefaultButton2, "Delete Session") = MsgBoxResult.Ok) Then

    If MsgBox("Are you sure ", MsgBoxStyle.Question + MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2, "Delete Record") = MsgBoxResult.Yes Then

    SessionsBindingSource.RemoveCurrent()

    SessionsBindingSource.EndEdit()

    Me.SessionsTableAdapter.Update(Me.ConfigurationDataSet.Sessions)

    End If

    End If

    End If

    End Sub


  • Spuddo

    No database changes would be made until you did

    MyTableAdapter.Update(myDataTable)

    ...you're just removing the current record from your local data cache, you'd have to update to commit changes...

    ...of course I'm replying to your post a year later so this is probably useless to you...


  • SiteGeek

    I can't get this to work.

    The item is still in my database.

    if (Validate() && (this.tblOPRBindingSource != null))

    {

    if (MessageBox.Show("Delete ", "Confirm Delete", MessageBoxButtons.YesNo,

    MessageBoxIcon.Question) == DialogResult.Yes)

    {

    this.tblOPRBindingSource.RemoveCurrent();

    this.tblOPRBindingSource.EndEdit();

    }

    }



  • Andy089

    Thank you Mark. 

    I was looking for this solution for awhole day for my C# project. Got a bit confuse when you said 'set the bindingNavigator to do nothing' until I found the part that I needed.

    For those who got confused like me.  Go to the designer of the form and change this line: 

    ie my navigator call NavTT,
    from:

    this.NavTT.DeleteItem = this.TTNavigatorDeleteItem;

    to:

    this.NavTT.DeleteItem = null;


  • love_1776

    Set the DeleteButton member on the BindingNavigator to Nothing and then hook the Delete Button Click yourself:

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        If (Me.Validate() And Not (CustomersBindingSource Is Nothing)) Then
             If (MsgBox("Delete ", MsgBoxStyle.YesNo) = MsgBoxResult.Yes) Then
                 CustomersBindingSource.RemoveCurrent()
                 CustomersBindingSource.EndEdit()
             End If
        End If
    End Sub

    mark



  • David Eccleston

    Mark, this is very helpful, thank you...Christophe
  • Jeremy Lawrence

    I can't get this to work.

    I'm getting an exception "Current item cannot be removed from the list because there is no current item".

    if (Validate() && (this.tblOPRBindingSource != null))

    {

    if (MessageBox.Show("Delete ", "Confirm Delete", MessageBoxButtons.YesNo,

    MessageBoxIcon.Question) == DialogResult.Yes)

    {

    this.tblOPRBindingSource.RemoveCurrent();

    this.tblOPRBindingSource.EndEdit();

    }

    }



  • Prevent 'RemoveCurrent' after BindingNavigator DeleteItem Click