An IEnumerable object that represents the underlying collection.
Example
All examples in this topic assume that the grid is bound to the Orders table of the Northwind database, unless stated otherwise.
The following example demonstrates how to delete the selected items from the underlying data view when the delete key is pressed via the PreviewKeyDown event.
PrivateSub DeleteSelectedRows(ByVal sender AsObject, ByVal e As KeyEventArgs)
Dim grid As DataGridControl = TryCast( sender, DataGridControl )
IfNot grid IsNothingThenIf e.Key = Key.Delete ThenIf grid.SelectedItems.Count > 0 Then' we keep a copy of the selected items because once the first item is deleted,
' the selected items are reset to 0.
Dim items As ArrayList = New ArrayList( grid.SelectedItems )
Dim dataView As DataView = TryCast( ( CType( grid.ItemsSource, _
DataGridCollectionView ) ).SourceCollection, DataView )
For i AsInteger = items.Count - 1 To 0 Step -1
dataView.Table.Rows.Remove( CType( items( i ), System.Data.DataRow ) )
Next i
grid.CurrentItem = grid.Items( 0 )
EndIfEndIfEndIfEnd Sub
Private void DeleteSelectedRows( Object sender, KeyEventArgs e )
{
DataGridControl grid = sender As DataGridControl;
If( grid != null )
{
If( e.Key == Key.Delete )
{
If( grid.SelectedItems.Count > 0 )
{
// we keep a copy of the selected items because once the first item Is deleted,
// the selected items are reset To 0 And the source may be automatically modified To
// reflect the New items.
ArrayList items = New ArrayList( grid.SelectedItems );
DataView dataView = ( ( DataGridCollectionView )grid.ItemsSource ).SourceCollection As DataView;
For( int i = items.Count - 1; i >= 0; i-- )
{
dataView.Table.Rows.Remove( ( System.Data.DataRow )items[ i ] );
}
grid.CurrentItem = grid.Items[ 0 ];
}
}
}
}
Requirements
Target Platforms: Windows 11, Windows 10, 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