Delete Events
The delete events are ment to support the deleting data process. They occur when the data in the RadGridView is about to be deleted or has been already deleted by the user.
Currently the delete events occur once for all the rows to be deleted. To get notified use the following events exposed by the RadGridView control:
Delete Events Lifecycle
It is important to know that each one of the delete events is fired only when the user is trying to delete row/rows in the RadGridView control by invoking the Delete command, for example via the Delete button on the keyboard.
The Deleting event always occurs when the user is about to delete the row/rows. The Deleting event can be canceled thus allowing you to stop the delete process. To do so set the Cancel property of the event arguments to True.
If the Deleting event is not canceled then the data is deleted and the Deleted event fires.
Deleting event
The Deleting event occurs when the row/rows is about to be deleted. It fires only once for all the selected rows (in case the SelectionMode is set to Multiple or Extended). The Deleting event handler receives two arguments:
The sender argument contains the RadGridView. This argument is of type object, but can be cast to the RadGridView type.
A GridViewDeletingEventArgs object. This object has the following properties:
Cancel - gets or sets the value indicating whether the event should be canceled.
Items - IEnumerable
You can subscribe to the Deleting event declaratively or runtime like this:
<telerik:RadGridView x:Name="gridView" Deleting="gridView_Deleting" />
this.gridView.Deleting += gridView_Deleting;
AddHandler Me.gridView.Deleting, AddressOf gridView_Deleting
' #endregion
'#region gridview-events-delete_7
AddHandler Me.gridView.Deleted, AddressOf gridView_Deleted
The Deleting event is cancelable. The example below uses the Deleting event to ask the user for confirmation before the deletion is performed.
protected IEnumerable<Object> itemsToBeDeleted;
private void gridView_Deleting(object sender, Telerik.Windows.Controls.GridViewDeletingEventArgs e)
{
//store the items to be deleted
itemsToBeDeleted = e.Items;
//cancel the event so the item is not deleted
//and wait for the user confirmation
e.Cancel = true;
//open the Confirm dialog
RadWindow.Confirm("Are you sure?", this.OnRadWindowClosed);
}
private void OnRadWindowClosed(object sender, WindowClosedEventArgs e)
{
//check whether the user confirmed
bool shouldDelete = e.DialogResult.HasValue ? e.DialogResult.Value : false;
if (shouldDelete)
{
foreach (var club in itemsToBeDeleted)
{
gridView.Items.Remove(club);
}
}
}
Protected itemsToBeDeleted As IEnumerable(Of Object)
Private Sub gridView_Deleting(ByVal sender As Object, ByVal e As Telerik.Windows.Controls.GridViewDeletingEventArgs)
'store the items to be deleted
itemsToBeDeleted = e.Items
'cancel the event so the item is not deleted
'and wait for the user confirmation
e.Cancel = True
'open the Confirm dialog
RadWindow.Confirm("Are you sure?", AddressOf Me.OnRadWindowClosed)
End Sub
Private Sub OnRadWindowClosed(ByVal sender As Object, ByVal e As WindowClosedEventArgs)
'check whether the user confirmed
Dim shouldDelete As Boolean = If(e.DialogResult.HasValue, e.DialogResult.Value, False)
If shouldDelete Then
For Each club In itemsToBeDeleted
gridView.Items.Remove(club)
Next club
End If
End Sub
Deleted event
The Deleted event occurs when the data has been deleted. The Deleted event handler receives two arguments:The sender argument contains the RadGridView. This argument is of type object, but can be cast to the RadGridView type. A GridViewDeletedEventArgs object. This object has the following properties:
- Items - IEnumerable
You can subscribe to the Deleted event declaratively or runtime like this:
<telerik:RadGridView x:Name="gridView" Deleted="gridView_Deleted" />
this.gridView.Deleted += gridView_Deleted;
AddHandler Me.gridView.Deleted, AddressOf gridView_Deleted