ComponentOne True DBGrid for .NET (2.0) Search HelpCentral 

C1TrueDBGrid.BeforeDelete Event

Occurs before a row is deleted.

[Visual Basic]

Public Event BeforeDelete As CancelEventHandler

[C#]

public event CancelEventHandler BeforeDelete

[Delphi]

public property BeforeDelete: CancelEventHandler read remove_BeforeDelete write add_BeforeDelete;

Remarks

When the user selects a record selector in the grid and presses DEL or CTRL+X, the BeforeDelete event is triggered to give the application a chance to override the user's action.

If event procedure sets the CancelEventArgs.Cancel property to True, the row is not deleted. Otherwise, the grid deletes the row and triggers the AfterDelete event.

The bookmark of the row selected for deletion is available in the collection provided by the SelectedRows property.

Note: If more than one row is selected, the error message "Cannot delete multiple rows" is displayed, and the BeforeDelete event will not be raised.

Example

The following code uses the BeforeDelete event to show the message "Are you sure you want to delete this record?" before a row is deleted:

·      Visual Basic

       Private Sub C1TrueDBGrid1_BeforeDelete(ByVal sender As System.Object, ByVal e As C1.Win.C1TrueDBGrid.CancelEventArgs) Handles C1TrueDBGrid1.BeforeDelete

           If MessageBox.Show("Are you sure you want to delete this record?", "Confirm Record Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then

               e.Cancel = True

           End If

       End Sub

·      C#

       private void c1TrueDBGrid1_BeforeDelete(object sender, C1.Win.C1TrueDBGrid.CancelEventArgs e)

       {

           if (MessageBox.Show ("Are you sure you want to delete this record?", "Confirm Record Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question)== DialogResult.No)

           {

               e.Cancel = true;

           }

       }

·      Delphi

       procedure C1TrueDBGrid1_BeforeDelete(sender: System.Object; e: C1.Win.C1TrueDBGrid.CancelEventArgs);

       begin

         if (MessageBox.Show('Are you sure you want to delete this record?', 'Confirm Record Delete', MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No) then

           e.Cancel := True;

       end;

Note: The AllowDelete property must be set to True for the BeforeDelete event to be raised.

See Also

C1TrueDBGrid Class | C1TrueDBGrid Members | C1.Win.C1TrueDBGrid Namespace


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.