Welcome to the Xceed Community | Help
Community Search  
More Search Options

Filtering data items (Filter Event)

Sort Posts: Previous Next
  •  10-08-2008, 3:53 PM Post no. 28120

    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;
        }
      }   
    }

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.