I have two xamdatagrids with same column structure and are binded with two different datatables from my viewmodel.
I am trying to achieve a scenario where if I apply Group By to any column of grid1 , the grid2 should also be grouped in a similar way.
Is there any event which I can use to achieve this ?
It is possible to achieve this functionality by using the Grouping
event of the XamDataGrid
control.
First, define the Grouping
event handler in the XAML:
<igDP:XamDataGrid x:Name="Grid1" Grouping="Grid1_Grouping">
Second, add the following code for Grid1_Grouping
:
private void Grid1_Grouping(object sender, Infragistics.Windows.DataPresenter.Events.GroupingEventArgs e)
{
// Clear all previous items from the groups collection
Grid2.FieldLayouts[0].SortedFields.Clear();
// Add the same groups set as currently defined in the Grid1
foreach (var g in e.Groups)
{
Grid2.FieldLayouts[0].SortedFields.Add(new FieldSortDescription { FieldName = g.FieldName, Direction = g.Direction, IsGroupBy = g.IsGroupBy });
}
}