xmlns:igDP=http://infragistics.com/DataPresenter
This topic explains how to use external grouping with the XamDataGrid™control .
The following topics are prerequisites to understanding this topic:
This topic contains the following sections:
External Grouping functionality will work similarly to how it works by default (i.e. internally) for xamDataGrid
from the UI perspective. Users will be able to drag and drop fields to and from the group-by area to group by the fields.
In order to use External Grouping you should set the GroupByEvaluationMode on FieldLayoutSettings to UseCollectionView . The GroupByEvaluationMode
enumeration has the following options:
This code example demonstrates how to use xamDataGrid’s external grouping feature. This example uses ListViewCollection as the xamDataGrid’s data source, because it implements the ICollectionView
interface. This collection is bound to the xamDataGrid and requires that the GroupByEvaluationMode
be set to UseCollectionView in order to use it for external grouping.
Start a new WPF Application project type named ExternalOperations , which includes the following:
A reference to the following NuGet package:
Infragistics.WPF.DataGrids
Classes
Item,
which inherits INotifyPropertyChanged. Item,
this inherits INotifyPropertyChanged. To see the complete code for this class, please refer to the Item class code example topic.
Utils
class, which creates a ListCollectionView
of random items. This is the data source, to which xamDataGrid will be bound. Please refer to the Creating ListCollectionView code example topic for this class’ complete code.
Starting window
Window named ExternalGrouping.xaml
, set as a starting window for the application.
Namespace definitions (located in the XAML part of the window, where your will place the mark-up for the xamDataGrid):
xmlns:igDP=http://infragistics.com/DataPresenter
xmlns:local="clr-namespace:ExternalOperations"
(this will be the case for projects named ExternalOperations. If you have chosen a different name, you should change this definition to reflect the new name).
The following picture illustrates the final rendering of the complied application using external grouping. From the UI perspective, there is no difference whether grouping operations occur externally or internally.
In XAML:
<Window x:Class="ExternalOperations.ExternalGrouping"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:igDP="http://infragistics.com/DataPresenter"
xmlns:local="clr-namespace:ExternalOperations"
Title="ExternalGrouping" Height="768" Width="1024">
<DockPanel LastChildFill="True">
<StackPanel Orientation="Vertical" VerticalAlignment="Stretch" DockPanel.Dock="Top">
<Button FontWeight="Bold" x:Name="btn100kExternal" Content="Bind to 100k items" Click="btn100kExternal_Click" Width="120" Margin="5"/>
<Label x:Name="lblExternalTimes" />
</StackPanel>
<igDP:XamDataGrid x:Name="xdg100kExternal" VerticalAlignment="Stretch" Grouping="xdg100kExternal_Grouping"
DataSourceResetBehavior="DiscardExistingRecords">
<igDP:XamDataGrid.FieldLayoutSettings>
<!-- Here GroupByEvaluationMode is set to UseCollectionView, in order to use the external grouping feature. -->
<igDP:FieldLayoutSettings GroupByEvaluationMode="UseCollectionView" FilterUIType="FilterRecord"/>
</igDP:XamDataGrid.FieldLayoutSettings>
<igDP:XamDataGrid.FieldSettings>
<igDP:FieldSettings AllowRecordFiltering="True" AllowSummaries="True" SummaryUIType="MultiSelect"
SummaryDisplayArea="BottomFixed" />
</igDP:XamDataGrid.FieldSettings>
</igDP:XamDataGrid>
</DockPanel>
</Window>
In Visual Basic:
Namespace ExternalOperations
''' <summary>
''' Interaction logic for ExternalGrouping.xaml
''' </summary>
Public Partial Class ExternalGrouping
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub btn100kExternal_Click(sender As Object, e As RoutedEventArgs)
xdg100kExternal.DataSource = Utils.CreateDataSource(100000)
End Sub
Private Sub xdg100kExternal_Grouping(sender As Object, e As GroupingEventArgs)
lblExternalTimes.Content = "Grouping..."
Dim start As DateTime = DateTime.Now
Dispatcher.BeginInvoke(DispatcherPriority.Background, New Action(Function()
lblExternalTimes.Content = "Time to group = "(DateTime.Now - start).TotalSeconds
End Function))
End Sub
End Class
End Namespace
In C#:
namespace ExternalOperations
{
/// <summary>
/// Interaction logic for ExternalGrouping.xaml
/// </summary>
public partial class ExternalGrouping : Window
{
public ExternalGrouping()
{
InitializeComponent();
}
private void btn100kExternal_Click(object sender, RoutedEventArgs e)
{
xdg100kExternal.DataSource = Utils.CreateDataSource(100000);
}
private void xdg100kExternal_Grouping(object sender, GroupingEventArgs e)
{
lblExternalTimes.Content = "Grouping...";
DateTime start = DateTime.Now;
Dispatcher.BeginInvoke(DispatcherPriority.Background,
new Action(
() =>
{
lblExternalTimes.Content = "Time to group = " + (DateTime.Now - start).TotalSeconds;
}
));
}
}
}
The following topics provide additional information related to this topic.
The following samples provide additional information related to this topic.