Filtering data items (Filter Event)
-
-
Xceed admin
-
-
-
Joined on 09-29-2008
-
Longueuil
-
Posts 443
-
-
|
Filtering data items (Filter Event)
The following example demonstrates how to filter the data items displayed in a grid using the Filter event. Only the data items whose ShipVia property value is "3" will be displayed in the grid.
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"> <Grid.Resources> <xcdg:DataGridCollectionViewSource x:Key="cvs_orders" Source="{Binding Source={x:Static Application.Current}, Path=Orders}" Filter="ShipViaFilter"/> </Grid.Resources>
<xcdg:DataGridControl x:Name="OrdersGrid" ItemsSource="{Binding Source={StaticResource cvs_orders}}"/> </Grid> | The following code provides the implementation of the ShipViaFilter event. This code should be placed in the "code-behind" of your XAML page.
VB.NET
Private Sub ShipViaFilter( sender As Object, e As FilterEventArgs ) Dim value As Object = CType( e.Item, System.Data.DataRow )( "ShipVia" )
If( Not value Is Nothing ) And ( Not value Is DBNull.Value ) Then If CInt( value ) = 3 Then
e.Accepted = True Else
e.Accepted = False End If End If
End Sub
C#
private void ShipViaFilter( object sender, FilterEventArgs e ) { object value = ( ( System.Data.DataRow )e.Item )[ "ShipVia" ];
if( ( value != null ) && ( value != DBNull.Value ) ) { if( ( int )value == 3 ) { e.Accepted = true; } else { e.Accepted = false; } } } |
|
|
|
|
|
|