In Focus

Forums - C# Corner

Forum guidelines
Mike Sportman

Mike Sportman

  • 1.5k
  • 10
  • 16.9k

How to stop DataGridView UserDeletingRow Event Firing for each row after e.Cancel = true

Feb 16 2011 9:50 AM

I am using a DataGridView in a Windows Form application.  The user is allowed to delete rows from the DataGridView.  During the DataGridView_UserDeletingRow event I would like to verify that the user really wants to delete the rows selected.  See code:

   private void DataGridViewSigns_UserDeletingRow( object sender, DataGridViewRowCancelEventArgs e )
      // Ask the user if they are sure?
      DialogResult usersChoice =
      MessageBox.Show( "Are you sure you want to delete the selected signs?\r\n"
      + DataGridViewSigns.SelectedRows.Count +
" signs will be deleted!",
      "Signs", MessageBoxButtons.OKCancel, MessageBoxIcon.Question );
      // cancel the delete event
      if ( usersChoice == DialogResult.Cancel )
      e.Cancel =


This works perfect if only a single row was selected to be deleted.  If multiple rows were selected and the user clicks the Cancel button then this event fires again for the next row in the selected group.
If the user clicks the cancel button I want the event to cancel, regardless of how many rows were selected.
Any ideas?

Answers (8)


Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now