Infragistics XamDataGrid Group在WPF中加载

时间:2013-11-20 12:44:44

标签: c# wpf infragistics xamdatagrid

如何为Infragistics的XamDataGrid设置一个给定属性的Group By on Load,并使该视图能够折叠已禁用的群组? 如果这是可能的,我会知道如何隐藏Group By小按钮。

我的环境是WPF和C#。

1 个答案:

答案 0 :(得分:4)

试试这个,

在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>

在codebehind中,

Private ObservableCollection<SampleBO> sampleCollection;

Public ObservableCollection<SampleBO> SampleCollection
{
    get
    {
        return this.sampleCollection;
    }   
}

您可以在Window Loaded事件或构造函数

中添加以下代码来加载和分组数据
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;

此外,对于扩展组,请使用以下事件,它最初用于扩展组。

private void xdgSample_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e)    
{    
if (e.Record.NestingDepth == 0)    
{    
    e.Record.IsExpanded = true;    
}    
}