The DataGridView has an event, UserDeletingRow, with the option to cancel the delete caused by pressing the Delete button of the keyboard. But if the user clicks the Delete toolstripbutton of the bindingnavigator, no such event exists. So what do you do to pop a messagebox asking the user to confirm to delete the row?
+1
A:
This is because the UserDeletingRow event is on the actual DataGridView. The DataGridView is bound to the external data (contained in your DataSet and linked by a BindingSource) as is the BindingNavigator. When you click delete on the BindingNavigator it is simply removing the current element selected in the BindingSource. You need to check the Click event on the delete button in the BindingNavigator and see where it is actually performing the delete to the BindingSource. You should be able to insert in a confirmation dialog between the delete item call and the click.
Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
If MsgBox("Are you sure", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
DeleteSelectedItem()
End If
End Sub
John Chuckran
2008-10-06 15:34:23