In a WPF app I'm developing I'd like to programmatically determine if a xamDataGrid has any filters configured or not.

I've configured an export function to Excel and would like to do a quick check to determine if a filter is active or not, if a filter is active then I'll present the user with the option to export filtered rows or not...

I can't find any suitable class members.

Any ideas?

有帮助吗?

解决方案

Found the answer guys n girls...

    var activeFilterCount = xamDataGrid1.FieldLayouts[0].RecordFilters.Sum(recordFilter => recordFilter.Conditions.Count);

其他提示

A XamDataGrid can have more than one field layout (hierarchical structure). In that case you need to consider all FieldLayouts not just the first one. So the complete solution is:

 public bool AreFiltersActive()
 {
   int activeFilterCount = 0;
   foreach (FieldLayout f in xamDataGrid.FieldLayouts)
   {
     activeFilterCount+= f.RecordFilters.Sum(recordFilter => recordFilter.Conditions.Count);
     //retrieve filter count per layout
   }        
   return activeFilterCount > 0;
   //If any fieldlayout has any filter active then the sum will be more than 0
 }

There is a reason why Filters are stored per FieldLayout in XamDataGrid.

In the earlier version they are stored in RecordManger against the grid. So it's the complete solution to iterate the all FieldLayouts.

Like Below Grid:Multiple Layout and Filters can be applied on every Layout/Level

XamDataGrid with multiple layouts

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top