Infragistics(R) NetAdvantage(R) Windows Forms
Delete(Boolean) Method
See Also  Example E-mail your feedback on this topic.
Infragistics.Win.UltraWinGrid Namespace > UltraGridRow Class > Delete Method : Delete(Boolean) Method

displayPrompt
Specifies whether to display the delete confirmation prompt.
Deletes the row.

Syntax

Visual Basic (Declaration) 
Public Overloads Function Delete( _
   ByVal displayPrompt As Boolean _
) As Boolean
C# 
public bool Delete( 
   bool displayPrompt
)

Parameters

displayPrompt
Specifies whether to display the delete confirmation prompt.

Example

Following code shows you how to delete a row programmatically by calling Delete on the UltraGridRow object.

Visual BasicCopy Code
Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid

  Private Sub Button69_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button69.Click

      ' Get the row to delete. In this case we will use the active row.
      Dim row As UltraGridRow = Me.UltraGrid1.ActiveRow

      If Not row Is Nothing Then
          ' Delete the row by calling Delete method. Enclose the call in a try-catch
          ' block so if there is an error, we can catch it and show an error message box
          ' to the user.
          Try
              row.Delete()

              ' IsDeleted should be true after a row has been deleted.
              Debug.WriteLine("Row.IsDeleted = " & row.IsDeleted)
          Catch exc As Exception
              MessageBox.Show("Error occured during deleting the row.\n" & exc.Message, _
                              "Error deleting row", MessageBoxButtons.OK, MessageBoxIcon.Error)
          End Try
      Else
          ' If there is no active row, then prompt the user to select one.
          MessageBox.Show("Please select a single row to delete.")
      End If

  End Sub
C#Copy Code
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;

private void button69_Click(object sender, System.EventArgs e)
{

	// Get the row to delete. In this case we will use the active row.
	UltraGridRow row = this.ultraGrid1.ActiveRow;

	if ( null != row )
	{
		// Delete the row by calling Delete method. Enclose the call in a try-catch
		// block so if there is an error, we can catch it and show an error message box
		// to the user.
		try
		{
			row.Delete( );

			// IsDeleted should be true after a row has been deleted.
			Debug.WriteLine( "Row.IsDeleted = " + row.IsDeleted );
		}
		catch ( Exception exc )
		{
			MessageBox.Show( "Error occured during deleting the row.\n" + exc.Message, 
					"Error deleting row", MessageBoxButtons.OK, MessageBoxIcon.Error );
		}
	}
	else
	{
		// If there is no active row, then prompt the user to select one.
		MessageBox.Show( "Please select a single row to delete." );
	}

}

Remarks

When a row is deleted, the BeforeRowsDeleted event is generated. Afterwards, the row is removed from the control and its corresponding record is deleted from the data source. If the record cannot be removed from the data source, the Error event is generated.

The DeleteSelectedRows method of the control can be invoked to delete all selected rows.

See Also