שתף באמצעות


BindingNavigator Delete Cancel

Question

Sunday, February 5, 2006 2:07 PM

I have a BindingNavigator and combobox tied to the same BindingSource. I want to allow the user to confirm a delete after hitting the delete button of the navigator. It appears that the row gets marked for deletion after my BindingNavigatorDeleteItem_Click event handler is processed. Is there no way to cancel the delete activity from within the delete click event? If not, then it becomes necessary to store a delete flag and catch another event to RejectChanges.

 

All replies (8)

Tuesday, August 8, 2006 12:01 PM ✅Answered | 3 votes

 

    With Microsoft's BindingNavigator you can neither ask for any confirmation nor have control over save, delete or add operations.

I use a ToolStrip with add, delete and save buttons on and the code is very simple:

to Add:

myBindingSource.AddNew();

to Delete:

myBindingSource.RemoveCurrent();

 

to Save:

this.Validate();

myBindingSource.Endedit();

tblMyAdapter.Update(myDataSet.myTable);

 

The BindingNavigator component for me is a very unnecessary and stupid thing to use.

 


Sunday, February 5, 2006 8:39 PM | 1 vote

You can clear BindingNavigator.DeleteItem in the properties window and write your own routine by handling BindingNavigatorDeleteItem.Click event.


Monday, February 6, 2006 1:09 PM

Not quite what I had in mind. Defeats the benefits of having the adds, deletes automatically generated. I want to use the generated behaviour of the BindingNavigator.DeleteItem IF the user confirms. It seems that this is a common programming feature that Microsoft should have designed a hook for. I will have the same case with the save. All items must pass validation first before executing SaveItem.


Thursday, January 25, 2007 2:21 PM

 

 

The BindingNavigator component for me is a very unnecessary and stupid thing to use.

I'm beginning to agree with you.... now that I've overwritten the navigation, add, deletion and save events.


Saturday, October 17, 2009 3:51 PM | 2 votes

First thing you will do is 
set BindingNavigator' s DeleteItem to none from the properties box
Doing this, the button will still show but the default event is gone.

Double click afterwards on the delete button and include a similar code like that,

Help with Code Tags

C# Syntax (Toggle Plain Text)

         private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)        {            if (MessageBox.Show("Sure you wanna delete?", "Warning", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)               bindingSource1.RemoveCurrent();        }

Monday, August 2, 2010 3:19 AM

bh, 

Hi, i've tried the following but i got an exception saying "Update requires a valid DeleteCommand when passed DataRow collection with deleted rows."  Any idea how to fix this exception?

Thanks so much.

Aron

 

private void bindingNavigatorDeleteItem_Click(object sender, EventArgs

e)

{

clientsBindingSource.RemoveCurrent();

 

this

.Validate();

 

this

.clientsBindingSource.EndEdit();

 

this.tableAdapterManager.UpdateAll(this

.ambtrans4DataSet);

}


Wednesday, June 15, 2011 7:19 PM | 2 votes

To cancel the delete event after a confirmation, get the confirmation before they actually click the button, on the MouseDown event, then set the Checked property to false if the answer is no.  Example:

 

    Private Sub BindingNavigatorDeleteItem_Mousedown(sender As System.Object, e As System.EventArgs)
 Handles BindingNavigatorDeleteItem.MouseDown
        Dim rs As MsgBoxResult = 
MsgBox("Are you sure you want to delete this record? This action cannot be undone.", vbYesNo,
 "Confirm Delete!")
        If rs = MsgBoxResult.No Then BindingNavigatorDeleteItem.Checked = False
    End Sub

Dan


Friday, March 21, 2014 5:01 PM

If your DataSource of BindingSource is DataTable in Dataset, use this:

Private Shared Sub Row_Deleting(ByVal sender As Object, ByVal e As DataRowChangeEventArgs) Handles MyDataSet.MyTable.RowDeleted
    If MessageBox.Show("Are you sure?", "Deleting", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.No Then
        e.Row.RejectChanges()
    End If
End Sub

Source: http://bytes.com/topic/visual-basic-net/answers/388418-delete-warning-bindingnavigator