Version

BeforeRowsDeleted Event

Occurs before one or more rows are deleted.
Syntax
'Declaration
 
Public Event BeforeRowsDeleted As BeforeRowsDeletedEventHandler
public event BeforeRowsDeletedEventHandler BeforeRowsDeleted
Event Data

The event handler receives an argument of type BeforeRowsDeletedEventArgs containing data related to this event. The following BeforeRowsDeletedEventArgs properties provide information specific to this event.

PropertyDescription
Cancel (Inherited from System.ComponentModel.CancelEventArgs) 
DisplayPromptMsg Whether to display prompt message.
Rows The rows (read-only)
Remarks

The rows argument returns a reference to a Rows collection that can be used to retrieve references to the UltraGridRow object or objects being deleted. You can use this reference to access any of the returned collection's properties or methods, as well as the properties or methods of the objects within the collection.

The displaypromptmsg argument enables you to hide the default confirmation message. This argument can be used to display your own dialog.

The cancel argument enables you to programmatically prevent the rows from being deleted. This argument can be used to prevent the user from deleting rows unless a certain condition is met.

This event is generated when rows are to be deleted, either programmatically, or by user interaction. To prevent the user from deleting rows, set the Override's UltraGridOverride.AllowDelete property to False. Rows can be deleted programmatically by invoking either the Delete method or the DeleteSelectedRows method.

The text displayed in the default confirmation dialog can be modified by setting the DialogStrings property.

The AfterRowsDeleted event, which occurs after rows are deleted, is generated after this event, provided cancel is not set to True.

Example
The following sample code uses BeforeRowsDeleted event to display a custom message box to prompt the user before deleting rows.

For an overview of how to handle events in Visual Basic or Visual C#, see Event Handlers in Visual Basic and Visual C#. For specific information and code examples illustrating how to consume events in your application, see Consuming Events in the .NET Framework Developer's Guide.

Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid

  Private Sub UltraGrid1_BeforeRowsDeleted(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeRowsDeletedEventArgs) Handles ultraGrid1.BeforeRowsDeleted

      ' Stop the grid from displaying it's message box.
      e.DisplayPromptMsg = False

      ' Display our own custom message box.
      Dim result As DialogResult = System.Windows.Forms.MessageBox.Show( _
              "Deleting " & e.Rows.Length.ToString() & " row(s). Continue ?", _
              "Delete rows?", _
              System.Windows.Forms.MessageBoxButtons.YesNo, _
              System.Windows.Forms.MessageBoxIcon.Question)

      ' If the user clicked No on the message box, cancel the deletion of rows.
      If System.Windows.Forms.DialogResult.No = result Then
          e.Cancel = True
      End If

  End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;

private void ultraGrid1_BeforeRowsDeleted(object sender, Infragistics.Win.UltraWinGrid.BeforeRowsDeletedEventArgs e)
{

	// Stop the grid from displaying it's message box.
	e.DisplayPromptMsg = false;
	 
	// Display our own custom message box.
	System.Windows.Forms.DialogResult result =
		System.Windows.Forms.MessageBox.Show( 
		"Deleting " + e.Rows.Length.ToString( ) + " row(s). Continue ?",
		"Delete rows?", 
		System.Windows.Forms.MessageBoxButtons.YesNo, 
		System.Windows.Forms.MessageBoxIcon.Question );
	 
	// If the user clicked No on the message box, cancel the deletion of rows.
	if ( System.Windows.Forms.DialogResult.No == result )
		e.Cancel = true;

}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also