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

Set AutoFilter Default Choice

Sort Posts: Previous Next
  •  09-12-2008, 7:56 PM Post no. 15231

    Set AutoFilter Default Choice

    I have a grid with an unbound column that uses a value converter.  The value converter checks the passed in value to see if it is null and then returns "Active" if it is and "Inactive" if it isn't.  (it's a deactivated date)

    Everything works great and the autofilter shows up with two choices in it.  Active and Inactive.  I would like the Active item to be checked by default so that the user only sees active items when the grid first loads.

    So,

    A.) is this possible and

    2.) how would one go about doing this?

    Thanks,

    Dave

     

  •  09-15-2008, 8:41 AM Post no. 15262 in reply to 15231

    Re: Set AutoFilter Default Choice

    Hi David,

      What can be done is to register to the DataGridControl's Loaded event and in this method, access the DataGridCollectionView and assign the desired Distinct Value (fetched from DataGridCollectionView.DistinctValues["fieldName"])  to the DataGridCollectionView.AutoFilterValues["fieldName"].

     

    DataGridCollectionView collectionView = testGrid.ItemsSource as DataGridCollectionView;

    IList distinctValues = collectionView.DistinctValues[ "MyDateTimeField" ];

    // We assume we want the first value of the distinctValues 

    collectionView.AutoFilterValues[ "MyDateTimeField" ].Add( distinctValues[ 0 ] ); 

     

    We assign a values present in the DistinctValues to assert the value we add to AutoFilterValues exists in DistinctValues. Else, if the object used to filter is not contained within the DataGridCollectionView, no DataItem will match this filter.


    Christian Nadeau
    Software Developer
    Xceed Software Inc.
  •  09-15-2008, 4:11 PM Post no. 15285 in reply to 15262

    Re: Set AutoFilter Default Choice

    Thanks for the reply Christian.

    I forgot to mention that the grid is bound to an empty list at first.  It is being used as the results list for a search.  I got a NullReferenceException on the myGrid.ItemsSource at first because the datasource wasn't set to anything when the screen is first loaded.  I got around this by simply creating an empty list.

    The next error (ArgumentOutOfRangeException) happens when trying to retrieve distinctValues[0].  There are no elements in the list as yet as there are no search results.

    What I am looking for is an event that takes place after the grid has bound itself to the datasource and calculated the DistinctValues so that I can set the default one.

    I know that there are only ever two distinct values so I tried:

    collectionView.AutoFilterValues["Status"].Add("Active");

    That didn't complain but it also didn't filter the list either.

    Thanks again,

    dave

  •  09-16-2008, 8:40 AM Post no. 15304 in reply to 15285

    Re: Set AutoFilter Default Choice

    Hi David,

      How did you configure your ValueConverter? Using a  DataGridCollecitonViewSource bound to an ObservableCollection, defining the ItemProperty to use the ValueConverter and doing exactly what you mentioned ( collectionView.AutoFilterValues["MyDateTime"].Add("Active") ), it will work perfectly.

     

    <xcdg:DataGridCollectionViewSource.ItemProperties>

       <xcdg:DataGridItemProperty Name="MyDateTime"  Converter="{StaticResource dateValueConverter}"/>

    </xcdg:DataGridCollectionViewSource.ItemProperties>

     

     

     


    Christian Nadeau
    Software Developer
    Xceed Software Inc.
  •  09-16-2008, 9:54 AM Post no. 15311 in reply to 15304

    Re: Set AutoFilter Default Choice

    Thanks Christian,

    Here is how my ItemProperty is defined:

    <xcdg:DataGridItemProperty Name="Status" ValuePath="InactivatedDate" DataType="{x:Type system:String}" Converter="{StaticResource ActiveStatusConverter}"/>

    I am bound to a ReadOnlyCollection.  I will try using an ObservableColleciton and let you know how I make out.

    [Update] 

    Changing to an ObservableCollection had no effect.

    [Update]

    I added the code to set the AutoFilterValue in the click event for the button that fires off the search after the results are returned and that works perfectly.

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