[GcSpreadGrid] フィルタのドロップダウンリストに表示される項目の並び順を変更する方法

文書番号 : 85097     文書種別 : 使用方法     登録日 : 2020/05/21     最終更新日 : 2020/05/21
文書を印刷する
対象製品
SPREAD for WPF 3.0J
詳細
FilterDropDownListオブジェクトのComparerプロパティを使用します。Comparerプロパティには、IComparerインタフェースを実装した独自の比較方法を定義したクラスを指定します。

◎サンプルコード(VB)
Imports GrapeCity.Windows.SpreadGrid

Class MainWindow
    Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
        GcSpreadGrid1.Columns(0).CanUserFilter = True

        GcSpreadGrid1.Cells(0, 0).Value = "aaa"
        GcSpreadGrid1.Cells(1, 0).Value = "bbb"
        GcSpreadGrid1.Cells(2, 0).Value = "ccc"
        GcSpreadGrid1.Cells(3, 0).Value = "ddd"

        Dim flist As FilterDropDownList = New FilterDropDownList() With {.Comparer = New MyComparer()}
        GcSpreadGrid1.Columns(0).FilterDropDownList = flist
    End Sub
End Class

Public Class MyComparer
    Implements IComparer

    Public Function Compare(x As Object, y As Object) As Integer Implements IComparer.Compare
        If x.ToString() = "ccc" Then
            Return -1
        End If

        If x.ToString() = "ddd" AndAlso y.ToString() = "bbb" Then
            Return -1
        End If

        Return Comparer.Default.Compare(x, y)
    End Function
End Class
◎サンプルコード(C#)
using GrapeCity.Windows.SpreadGrid;

public partial class MainWindow : Window
{
    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        gcSpreadGrid1.Columns[0].CanUserFilter = true;

        gcSpreadGrid1.Cells[0, 0].Value = "aaa";
        gcSpreadGrid1.Cells[1, 0].Value = "bbb";
        gcSpreadGrid1.Cells[2, 0].Value = "ccc";
        gcSpreadGrid1.Cells[3, 0].Value = "ddd";

        FilterDropDownList flist = new FilterDropDownList() { Comparer = new MyComparer() };
        gcSpreadGrid1.Columns[0].FilterDropDownList = flist;
    }
}

public class MyComparer : IComparer
{
    public int Compare(object x, object y)
    {
        if (x.ToString() == "ccc")
        {
            return -1;
        }

        if (x.ToString() == "ddd" && y.ToString() == "bbb")
        {
            return -1;
        }

        return Comparer.Default.Compare(x, y);
    }
}