Home Forums WPF controls Xceed DataGrid for WPF 2 Filtering questions

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #26916 |

    Hello,

     

    I have 2 questions about filtering.  I am looking at the SolidFoundation example that comes with the DataGrid.  Perhaps I am just blind but I am wondering in that example how do you prevent certain columns from having the Filtering ability?  I turned on Filtering in my app and all the columns are now filtering.

     

    My second question is could someone show me how to do a filter in code?  Basically the filtering is working the way I would like but I want the application when it starts up to be filtered in a certain way in a certain column.  (In other words lets say the column was called  “States”  and lets say when I launch the app I only want to show all the rows that have  “New York” in that filter….how would you do that in c# code?

     

    Thanks!

     

    Imported from legacy forums. Posted by David (had 1208 views)

    Xceed Support
    Member
    Post count: 5658

    The auto-filter drop down will appear when distinct values are calculated for a data-grid item property. That said, you can set the DefaultCalculateDistinctValues property of the DataGridCollectionViewSource to false (by defaul true)  and explicitly set the CalculateDistinctValues property of each data-grid item property for which you want the auto-filtering to true.

    If you are using the DataGridCollectionView in code,  you will need to explicitly set the CalculateDistinctValues of the data-grid item properties for which you don’t want auto-filtering to false.

    As for providing an inital filter:

    DataGridCollectionView view = new DataGridCollectionView( App.Orders.DefaultView );
    view.AutoFilterMode =
    AutoFilterMode.And;
    view.AutoFilterValues[
    “ShipCountry” ].Add( “Canada” );
    this.OrdersGrid.ItemsSource = view;

     

    Imported from legacy forums. Posted by Jenny [Xceed] (had 1707 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks!  That works great!

     I tried doing a filter on a detail row…and I keep getting a exception.

     

    table_Site_ID.ChildRelations.Add(

    new DataRelation(“Site_Contacts”, table_Site_ID.Columns[“ID”], table_Site_Contacts.Columns[“Site_ID”]));

    table_Site_ID.ChildRelations.Add(

    new DataRelation(“Scheduler_To_Site_ID”, table_Site_ID.Columns[“ID”], table_Scheduler.Columns[“ID”] ));//table_Scheduler.Columns[“ID”]));

    DataGridCollectionView dataGridCollectionView = new DataGridCollectionView(table_Site_ID.DefaultView);

    dataGridCollectionView.AutoFilterMode =

    AutoFilterMode.And;

    dataGridCollectionView.DetailDescriptions[

    “Scheduler_To_Site_ID”].AutoFilterMode = AutoFilterMode.And;

    // the line below is the line that is throwing a exception   (System.Windows.Markup.XamlParseException was unhandled)

    dataGridCollectionView.DetailDescriptions[

    “Scheduler_To_Site_ID”].AutoFilterValues[“Task_Status”].Add((long)1);

     

    dataGridControl_Site_ID.ItemsSource = dataGridCollectionView;

     

    When I try to do a filter on the parent row with the same exact field type and similar code it works fine for the parent row.  Any ideas on what is going on here?

    Imported from legacy forums. Posted by David (had 554 views)

    Xceed Support
    Member
    Post count: 5658

    This is a normal behavior and by design: DetailDescriptions are used to configure the Details inside the grid. For each Detail, a DataGridCollectionView is created by the DataGridControl when the detail is expanded. Otherwise, the data related to those details is unaccessible. The Auto-Filtering feature is managed by the DataGridCollectionView and the AutoFilterValues[FieldName] Dictionnary must be initialized by the DataGridCollection with the field names in the Detail. 

    That is exactly the case in your scenario: you are attempting to access one of the field in a DataGridCollectionView’s DetailDescription before it is actually created. This is not currently supported. I’ll enter a feature request and we’ll keep you informed on this thread.

    Imported from legacy forums. Posted by Chris [Xceed] (had 679 views)

    User (Old forums)
    Member
    Post count: 23064

    Hmmmm well that makes more sense now….

    Would this be added in 2.2?  Or some version after would you know?

    Imported from legacy forums. Posted by David (had 566 views)

    Xceed Support
    Member
    Post count: 5658

    At the moment, we can’t say if it will be implemented or not, neither in which version it would be. We’ll keep you informed as soon as we have further informations.

    Imported from legacy forums. Posted by Chris [Xceed] (had 503 views)

    User (Old forums)
    Member
    Post count: 23064

    This actually brings up another question….

    I am wondering if you can use a DataTableDictionary like you can in the master column?  (Basically can you make a combobox with a list of items the user can pick like you can when its the top parent)?

     

    Imported from legacy forums. Posted by David (had 577 views)

    Xceed Support
    Member
    Post count: 5658

    Yes. You can activate auto-filtering in the details by setting the DataGridDetailDescription’s (defined in the DataGridCollectionView[Source]) AutoFilterMode property to And or Or.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 827 views)

    User (Old forums)
    Member
    Post count: 23064

    I think I have 1 more filtering question….

     

    This thread was great about showing how to do a pre-defined filter before you load the grid up.  But if the grid is already loaded up and I have a button that would have a few defined filters…how would I go about doing that?  (So in other words the Datagrid us already filled with data…the user pushes a button that will add some filters to a certain column….how would you go about that in code?)

     

    Imported from legacy forums. Posted by David (had 627 views)

    Xceed Support
    Member
    Post count: 5658

    For the master level, you can do exactly as in your previous post:

    DataGridCollectionView dataGridCollectionView = grid.ItemsSource as DataGridCollecitonView (Get your DataGridCollectionView used as ItemsSource)

    dataGridCollectionView.AutoFilterMode =

    AutoFilterMode.And;

    dataGridCollectionView.

    AutoFilterValues[AutoFilteredField].Add( FilterValue );

    dataGridCollectionView.

    AutoFilterValues[AutoFilteredField].Add( FilterValue1 );

    … (for all values required for this field)

    dataGridCollectionView.

    AutoFilterValues[AutoFilteredField2].Add( FilterValue2 );

    … (for all values required for this other field)

     

    For the detail level, it is not yet supported as mentionned earlier.

    Imported from legacy forums. Posted by Chris [Xceed] (had 1962 views)

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.