Hello,
I have 2 xamdatafrids that are binded to the same DataSource.
Each Datagrid have different subset of fields. One binded to properties A,B and the other to C,D.
I want to be able to filter field A and get both table be filters.
So if after the filter I get 2 records I want to see the same 2 records in the second table.
I don't want to use hiding of fields, because my original table have much more fields.
I'd appreciate your help.
Anna.
Can you help me with applying filter from one grid to other?
I can't find a way to do this.
I can get the filters like that :
myDataGrid1.FieldLayouts[0].RecordFilters
but I can't copy it like this: myDataGrid2.FieldLayouts[0].RecordFilters = myDataGrid1.FieldLayouts[0].RecordFilters
I wrote this code:
private void DataPresenterBase_OnRecordFilterChanged(object sender, RecordFilterChangedEventArgs e)
{
foreach (var filter in datagrid1.FieldLayouts[0].RecordFilters)
if (filter.Conditions.Count > 0)
var f = datagrid2.FieldLayouts[0].RecordFilters.FirstOrDefault(r => r.FieldName == filter.FieldName);
f.Conditions.Clear();
foreach (var conditions in filter.Conditions)
f.Conditions.Add(conditions);
}
but I get datagrid2.FieldLayouts[0].RecordFilters.Count == 0 before I first enter the tabItem that contains datagrid2,
and after RecordFilters gets populated it doesn't contain the filters of hidden fields.
Hi Anna,
Did you set the FilterEvaluationMode on the second data grid to "Default" as well? The only time the RecordFilters collection is empty is when it's using the CollectionView option. Even with UnboundFields, if the evaluation mode is Default then there should be RecordFilters in there.
I did set FilterEvaluationMode to default.
The problem is that each datagrid is in different tabItem of TabControl.
So if I set the filter before I go over all tabs I get RecordFilters empty for those datagrids that haven't been visited yet.
It's like the filters a populated only after the datagrid was visualized first time.
Yeah I see that too. Looks like we'll have to force them to "visualize" so the filters can set. Either that or your application changes how the filter is applied. Rather than change the filter of other datagrids when changing the current datagrid, wait till the other datagrid is brought into view and then copy the filters from the first datagrid over to the newly visible datagrid.
You can force a grid in another tab to render itself by calling Measure and Arrange:
datagrid2.Measure(new Size(tab2.ActualWidth, tab2.ActualHeight));datagrid2.Arrange(new Rect(0, 0, tab2.ActualWidth, tab2.ActualHeight));
This will force the datagrid to render which will setup the RecordFilters for it.