The following example demonstrates how to enable automatic filtering, disabling it for the columns that will not support it and filtering the distinct values of the ShipCity column.
| XAML |
Copy Code |
|---|---|
<Grid> <Grid.Resources> <xcdg:DataGridCollectionViewSource x:Key="cvs_orders" Source="{Binding Source={x:Static Application.Current}, Path=Orders}" AutoFilterMode="And" DistinctValuesConstraint="Filtered" AutoCreateItemProperties="False"> <xcdg:DataGridCollectionViewSource.ItemProperties> <xcdg:DataGridItemProperty Name="ShipCountry" Title="Country"/> <xcdg:DataGridItemProperty Name="ShipCity" Title="City"/> <xcdg:DataGridItemProperty Name="ShipAddress" Title="Address"/> <xcdg:DataGridItemProperty Name="ShipPostalCode" Title="Postal Code"/> <xcdg:DataGridItemProperty Name="ShipName" Title="Name" CalculateDistinctValues="False"/> <xcdg:DataGridItemProperty Name="OrderDate" Title="Order Date" CalculateDistinctValues="False"/> <xcdg:DataGridItemProperty Name="Freight" CalculateDistinctValues="False"/> </xcdg:DataGridCollectionViewSource.ItemProperties> </xcdg:DataGridCollectionViewSource> </Grid.Resources> <xcdg:DataGridControl x:Name="OrdersGrid" ItemsSource="{Binding Source={StaticResource cvs_orders}}"/> </Grid> | |
| VB.NET |
Copy Code |
|---|---|
Dim view As New DataGridCollectionView( Orders, GetType( System.Data.DataRow ), False, False ) view.AutoFilterMode = AutoFilterMode.And view.DistinctValuesConstraint = DistinctValuesConstraint.Filtered view.ItemProperties.Add( New DataGridItemProperty( "ShipCountry", GetType( String ) ) ) view.ItemProperties.Add( New DataGridItemProperty( "ShipCity", GetType( String ) ) ) view.ItemProperties.Add( New DataGridItemProperty( "ShipAddress", GetType( String ) ) ) view.ItemProperties.Add( New DataGridItemProperty( "ShipPostalCode", GetType( String ) ) ) Dim shipName As New DataGridItemProperty( "ShipName", GetType( String ) ) shipName.CalculateDistinctValues = False view.ItemProperties.Add( shipName ) Dim orderDate As New DataGridItemProperty( "OrderDate", GetType( DateTime ) ) orderDate.CalculateDistinctValues = False view.ItemProperties.Add( orderDate ) Dim freight As New DataGridItemProperty( "Freight", GetType( Double ) ) freight.CalculateDistinctValues = False view.ItemProperties.Add( freight ) dataGridControl.ItemsSource = view | |
| C# |
Copy Code |
|---|---|
DataGridCollectionView view = new DataGridCollectionView( Orders, typeof( System.Data.DataRow ), false, false ); view.AutoFilterMode = AutoFilterMode.And; view.DistinctValuesConstraint = DistinctValuesConstraint.Filtered; view.ItemProperties.Add( new DataGridItemProperty( "ShipCountry", typeof( string ) ) ); view.ItemProperties.Add( new DataGridItemProperty( "ShipCity", typeof( string ) ) ); view.ItemProperties.Add( new DataGridItemProperty( "ShipAddress", typeof( string ) ) ); view.ItemProperties.Add( new DataGridItemProperty( "ShipPostalCode", typeof( string ) ) ); DataGridItemProperty shipName = new DataGridItemProperty( "ShipName", typeof( string ) ); shipName.CalculateDistinctValues = false; view.ItemProperties.Add( shipName ); DataGridItemProperty orderDate = new DataGridItemProperty( "OrderDate", typeof( DateTime ) ); orderDate.CalculateDistinctValues = false; view.ItemProperties.Add( orderDate ); DataGridItemProperty freight = new DataGridItemProperty( "Freight", typeof( double ) ); freight.CalculateDistinctValues = false; view.ItemProperties.Add( freight ); dataGridControl.ItemsSource = view; | |