LoginSignup
6
3

More than 5 years have passed since last update.

15行で試す 高機能グリッドとピボットテーブル(XamDataGrid, XamPivotGrid)

Last updated at Posted at 2018-04-13

WPFのサードパーティー製品であるInfragistics WPFについて、
高機能グリッドや、ピボットなど魅力的なコントロールが数多く含まれています。
が、高機能ゆえに複雑な設定が必要では?と思われるかもしれませんが、
グリッドとピボットを機能あわせても最小限のコード量(約15行)で動かすことができます!

サンプルコード

MainWindow.xaml.cs
        private void SettingDatas<T>(IEnumerable<T> datas)
        {
            // Gridへのデータソースを設定
            xamDataGrid.DataSource = datas;
            // Pivotに対するデータソースを設定
            FlatDataSource flatData = new FlatDataSource()
            {
                ItemsSource = datas,
                ConnectionSettings = new FlatDataConnectionSettings(){ ItemsSource = datas}
            };
            xamPivot.DataSource = flatData;
            xamPivotDataSelector.DataSource = flatData;
        }
MainWindow.xaml
        <igWPF:XamDataGrid x:Name="xamDataGrid">
            <igWPF:XamDataGrid.FieldSettings>
                <igWPF:FieldSettings AllowRecordFiltering="true" />
            </igWPF:XamDataGrid.FieldSettings>
        </igWPF:XamDataGrid>
        <ig:XamPivotGrid x:Name="xamPivot"/>
        <ig:Expander><ig:XamPivotDataSelector x:Name="xamPivotDataSelector" /></ig:Expander>

あとは表示したいデータを設定するのみ。

    // サンプルデータを設定
    SettingDatas<SampleData>(datas);
    public class SampleData
    {
        public DateTime Date { get; set; }
        public string Category { get; set; }
        public string Name { get; set; }
        public decimal Budget { get; set; }
        public decimal Actual { get; set; }
    }

グリッドの操作

グリッド.gif

ピボットの操作

ピボット.gif

サンプルコード含め、GitHubにコミットしています。
https://github.com/furugen/infragistics-wpf-xampivotgrid-001
※別途、Infragistics製品が必要となりますので、ご興味があればインストールしてお試しください。
https://jp.infragistics.com/products/wpf

次回はExcelのデータを読み込みや、チャート機能の連携に関する記事を書こうと思います。
(InfragisticsのExcelライブラリもかなり強力です!)

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3