Welcome to the Xceed Community Sign in | Join | Help
Community Search  

2 Filtering questions

Sort Posts: Previous Next
  •  04-24-2008, 3:03 PM Post no. 11714

    2 Filtering questions

    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!

     

  •  04-24-2008, 3:38 PM Post no. 11719 in reply to 11714

    Re: 2 Filtering questions

    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;

     


    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
    Filed under:
  •  04-25-2008, 2:08 PM Post no. 11754 in reply to 11719

    Re: 2 Filtering questions

    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?

  •  04-25-2008, 3:13 PM Post no. 11755 in reply to 11754

    Re: 2 Filtering questions

    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.


    Christian Nadeau
    Software Developer
    Xceed Software Inc.
  •  04-25-2008, 3:38 PM Post no. 11757 in reply to 11755

    Re: 2 Filtering questions

    Hmmmm well that makes more sense now....

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

  •  04-25-2008, 4:01 PM Post no. 11758 in reply to 11757

    Re: 2 Filtering questions

    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.


    Christian Nadeau
    Software Developer
    Xceed Software Inc.
  •  04-29-2008, 12:58 PM Post no. 11834 in reply to 11758

    Re: 2 Filtering questions

    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)?

     

  •  04-29-2008, 1:14 PM Post no. 11835 in reply to 11834

    Re: 2 Filtering questions

    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.
    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  05-09-2008, 10:13 AM Post no. 12123 in reply to 11835

    Re: 2 Filtering questions

    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?)

     

  •  05-09-2008, 3:14 PM Post no. 12135 in reply to 12123

    Re: 2 Filtering questions

    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.


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