Reputation: 1652
How can I set a Group By on Load for a given property for the XamDataGrid from Infragistics, and making the view of this uncollapsed with the ability to collapse the group disabled? If this is possible I would know how I can hide the Group By small button as well.
My environment is WPF and C#.
Upvotes: 0
Views: 4607
Reputation: 305
Try this,
In Xaml,
<igDP:XamDataGrid x:Name="xdgSample" DataSource="{Binding SampleCollection}" InitializeRecord="xdgSample_InitializeRecord">
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>
<igDP:Field Name="field1" Label="Field1"/>
<igDP:Field Name="field2" Label="Field2"/>
<igDP:Field Name="field3" Label="Field3"/>
<igDP:Field Name="field4" Label="Field4"/>
<igDP:Field Name="field5" Label="Field5"/>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings AllowFieldMoving="No"
AllowDelete="False"
AutoGenerateFields="False"
AutoFitMode="ExtendLastField"
SelectionTypeRecord="Single"
FilterUIType="LabelIcons"
GroupByExpansionIndicatorVisibility="Collapsed">
</igDP:FieldLayoutSettings>
</igDP:XamDataGrid.FieldLayoutSettings>
</igDP:XamDataGrid>
In codebehind,
Private ObservableCollection<SampleBO> sampleCollection;
Public ObservableCollection<SampleBO> SampleCollection
{
get
{
return this.sampleCollection;
}
}
You can put below code to load and grouping data in Window Loaded event or Constructor,
this.sampleCollection = your collection/List;
this.OnPropertyChange("SampleCollection");
this.xdgSample.FieldLayouts[0].SortedFields.Add(new FieldSortDescription
{
IsGroupBy = true,
Field = this.xamInputList.FieldLayouts[0].Fields["field2"],
Direction = System.ComponentModel.ListSortDirection.Ascending
});
this.xdgSample.FieldLayoutSettings.HeaderPlacement = HeaderPlacement.OnTopOnly;
this.xdgSample.FieldLayoutSettings.HeaderPlacementInGroupBy = HeaderPlacementInGroupBy.WithDataRecords;
Also,for expanded groups,use below event,it's for expanding group initially.
private void xdgSample_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e)
{
if (e.Record.NestingDepth == 0)
{
e.Record.IsExpanded = true;
}
}
Upvotes: 5