[GcSpreadGrid] コードでソートを実行したい

文書番号 : 85066     文書種別 : 使用方法     登録日 : 2020/03/30     最終更新日 : 2020/03/30
文書を印刷する
対象製品
SPREAD for WPF 3.0J
詳細
SpreadSortDescriptionクラスに並び替える列の情報を設定し、SortDescriptionsプロパティに追加することで、ソートが実現します。詳細については製品ヘルプの以下の項目で解説しています。

[SPREAD for WPF 3.0J - GcSpreadGrid]
- [開発者ガイド]
 - [ソート]
  - [コーディングによるソート]


◎サンプルコード(VB)
Public Sub New()
    InitializeComponent()

    ' テストデータの設定
    GcSpreadGrid1.SetCellValue(0, 0, 10)
    GcSpreadGrid1.SetCellValue(1, 0, 100)
    GcSpreadGrid1.SetCellValue(2, 0, 50)
    GcSpreadGrid1.SetCellValue(3, 0, 40)
    GcSpreadGrid1.SetCellValue(4, 0, 80)
    GcSpreadGrid1.SetCellValue(5, 0, 1)
    GcSpreadGrid1.SetCellValue(6, 0, 65)
    GcSpreadGrid1.SetCellValue(7, 0, 20)
    GcSpreadGrid1.SetCellValue(8, 0, 30)
    GcSpreadGrid1.SetCellValue(9, 0, 35)
End Sub

Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
    Dim sortDirect As System.ComponentModel.ListSortDirection = System.ComponentModel.ListSortDirection.Ascending
    If (GcSpreadGrid1.SortDescriptions.Count <> 0) Then
        sortDirect = GcSpreadGrid1.SortDescriptions(0).Direction
        GcSpreadGrid1.SortDescriptions.Clear()
    End If

    Dim sortDes As GrapeCity.Windows.SpreadGrid.SpreadSortDescription = New GrapeCity.Windows.SpreadGrid.SpreadSortDescription() With {.ColumnIndex = 0}
    sortDes.Direction = IIf((sortDirect = System.ComponentModel.ListSortDirection.Ascending), System.ComponentModel.ListSortDirection.Descending, System.ComponentModel.ListSortDirection.Ascending)
    GcSpreadGrid1.SortDescriptions.Add(sortDes)
End Sub

◎サンプルコード(C#)
public MainWindow()
{
    InitializeComponent();

    // テストデータの設定
    gcSpreadGrid1.SetCellValue(0, 0, 10);
    gcSpreadGrid1.SetCellValue(1, 0, 100);
    gcSpreadGrid1.SetCellValue(2, 0, 50);
    gcSpreadGrid1.SetCellValue(3, 0, 40);
    gcSpreadGrid1.SetCellValue(4, 0, 80);
    gcSpreadGrid1.SetCellValue(5, 0, 1);
    gcSpreadGrid1.SetCellValue(6, 0, 65);
    gcSpreadGrid1.SetCellValue(7, 0, 20);
    gcSpreadGrid1.SetCellValue(8, 0, 30);
    gcSpreadGrid1.SetCellValue(9, 0, 35);
}

private void button1_Click(object sender, RoutedEventArgs e)
{
    System.ComponentModel.ListSortDirection sortDirect = System.ComponentModel.ListSortDirection.Ascending;
    if ((gcSpreadGrid1.SortDescriptions.Count != 0))
    {
        sortDirect = gcSpreadGrid1.SortDescriptions[0].Direction;
        gcSpreadGrid1.SortDescriptions.Clear();
    }

    GrapeCity.Windows.SpreadGrid.SpreadSortDescription sortDes = new GrapeCity.Windows.SpreadGrid.SpreadSortDescription { ColumnIndex = 0 };
    sortDes.Direction = ((sortDirect == System.ComponentModel.ListSortDirection.Ascending) ? System.ComponentModel.ListSortDirection.Descending : System.ComponentModel.ListSortDirection.Ascending);
    gcSpreadGrid1.SortDescriptions.Add(sortDes);
}
関連情報