Gustav Brock
gustav at cactus.dk
Mon Oct 6 16:28:42 CDT 2008
Hi Doug You are most welcome. Could you provide a link, please? Problem is, however, that this suggestion was one of my first attempts - only to find out that this event is fired _after_ the actual deleting has been carried out - and as it carries no "Cancel" parameter or similar, it can only be used for something else you wish to do when that toolbarbutton has been clicked. While, coming from Access, I still wonder why this simple feature is not ready-built, I'm not in the mood to start modifying the native bindingnavigator as my workaround functions very well. As I wanted the deleted row (when confirmed) to be removed from the database at once, I included this code: private void dataGridView1_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e) { if (e.RowCount > 0) { this.Cursor = Cursors.WaitCursor; // Delete from the source the deleted row. this.dessinNoBindingSource.EndEdit(); this.productTableAdapter.Update(this.karnelia.Product); this.Cursor = Cursors.Default; } } This also executes after the user has selected a row and pressed the Delete key. /gustav >>> dbdoug at gmail.com 06-10-2008 17:58 >>> Hi Gustav: I took a bit of a liberty and submitted your question on StackOverflow. I hope you don't mind. I was curious to see what feedback (if any) I got for a vb question, as the site is very C# intensive. Anyway, here's the answer I got after half an hour or so: 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 Doug Steele On Mon, Oct 6, 2008 at 1:18 AM, Gustav Brock <Gustav at cactus.dk> wrote: > Hi all > > 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. Why? > > So what do you do to pop a messagebox asking the user to confirm to delete > the row?