MESCIUS SPREAD for Windows Forms 15.0J サンプルコード集
コードからテーブルのフィルタの実行

TableViewクラスのFilterメソッド呼び出しにより、任意のタイミング(ボタンクリックイベントなど)でテーブルのフィルタリングを実行させることができます。

【実行例】

  • フィルタリングをクリアするには、Filterメソッドの第2引数にNothing(C#ではnull)を設定します(table.Filter(3, Nothing))。

private void Form1_Load(object sender, EventArgs e)
{
    // テストデータの設定
    fpSpread1.ActiveSheet.Cells[0, 0].Value = "名前";
    fpSpread1.ActiveSheet.Cells[0, 1].Value = "性別";
    fpSpread1.ActiveSheet.Cells[0, 2].Value = "報酬";
    fpSpread1.ActiveSheet.Cells[0, 3].Value = "職業";
    fpSpread1.ActiveSheet.Cells[1, 0].Value = "佐藤";
    fpSpread1.ActiveSheet.Cells[1, 1].Value = "男";
    fpSpread1.ActiveSheet.Cells[1, 2].Value = 300000;
    fpSpread1.ActiveSheet.Cells[1, 3].Value = "教師";
    fpSpread1.ActiveSheet.Cells[2, 0].Value = "高橋";
    fpSpread1.ActiveSheet.Cells[2, 1].Value = "男";
    fpSpread1.ActiveSheet.Cells[2, 2].Value = 300000;
    fpSpread1.ActiveSheet.Cells[2, 3].Value = "エンジニア";
    fpSpread1.ActiveSheet.Cells[3, 0].Value = "木村";
    fpSpread1.ActiveSheet.Cells[3, 1].Value = "女";
    fpSpread1.ActiveSheet.Cells[3, 2].Value = 320000;
    fpSpread1.ActiveSheet.Cells[3, 3].Value = "教師";
    fpSpread1.ActiveSheet.Cells[4, 0].Value = "高山";
    fpSpread1.ActiveSheet.Cells[4, 1].Value = "女";
    fpSpread1.ActiveSheet.Cells[4, 2].Value = 270000;
    fpSpread1.ActiveSheet.Cells[4, 3].Value = "会計士";
    // テーブルの追加
    fpSpread1.ActiveSheet.AddTable("table1", 0, 0, 5, 4);
}
 
private void button1_Click(object sender, EventArgs e)
{
    // フィルタリングの実行
    FarPoint.Win.Spread.TableView table = fpSpread1.ActiveSheet.GetTable("table1");
    FarPoint.Win.Spread.FilterItemValue fi1 = new FarPoint.Win.Spread.FilterItemValue("エンジニア");
    FarPoint.Win.Spread.FilterItemValue fi2 = new FarPoint.Win.Spread.FilterItemValue("会計士");
    FarPoint.Win.Spread.MultiValuesFilterItem multifilter = new FarPoint.Win.Spread.MultiValuesFilterItem(new FarPoint.Win.Spread.FilterItemValue[] { fi1, fi2 });
    table.Filter(3, multifilter);
}
Private Sub Table_02_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    ' テストデータの設定
    FpSpread1.ActiveSheet.Cells(0, 0).Value = "名前"
    FpSpread1.ActiveSheet.Cells(0, 1).Value = "性別"
    FpSpread1.ActiveSheet.Cells(0, 2).Value = "報酬"
    FpSpread1.ActiveSheet.Cells(0, 3).Value = "職業"
    FpSpread1.ActiveSheet.Cells(1, 0).Value = "佐藤"
    FpSpread1.ActiveSheet.Cells(1, 1).Value = "男"
    FpSpread1.ActiveSheet.Cells(1, 2).Value = 300000
    FpSpread1.ActiveSheet.Cells(1, 3).Value = "教師"
    FpSpread1.ActiveSheet.Cells(2, 0).Value = "高橋"
    FpSpread1.ActiveSheet.Cells(2, 1).Value = "男"
    FpSpread1.ActiveSheet.Cells(2, 2).Value = 300000
    FpSpread1.ActiveSheet.Cells(2, 3).Value = "エンジニア"
    FpSpread1.ActiveSheet.Cells(3, 0).Value = "木村"
    FpSpread1.ActiveSheet.Cells(3, 1).Value = "女"
    FpSpread1.ActiveSheet.Cells(3, 2).Value = 320000
    FpSpread1.ActiveSheet.Cells(3, 3).Value = "教師"
    FpSpread1.ActiveSheet.Cells(4, 0).Value = "高山"
    FpSpread1.ActiveSheet.Cells(4, 1).Value = "女"
    FpSpread1.ActiveSheet.Cells(4, 2).Value = 270000
    FpSpread1.ActiveSheet.Cells(4, 3).Value = "会計士"
   ' テーブルの追加
    FpSpread1.ActiveSheet.AddTable("table1", 0, 0, 5, 4)
End Sub
 
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    ' フィルタリングの実行
    Dim table As FarPoint.Win.Spread.TableView = FpSpread1.ActiveSheet.GetTable("table1")
    Dim fi1 As FarPoint.Win.Spread.FilterItemValue = New FarPoint.Win.Spread.FilterItemValue("エンジニア")
    Dim fi2 As FarPoint.Win.Spread.FilterItemValue = New FarPoint.Win.Spread.FilterItemValue("会計士")
    Dim multifilter As New FarPoint.Win.Spread.MultiValuesFilterItem(New FarPoint.Win.Spread.FilterItemValue() {fi1, fi2})
    table.Filter(3, multifilter)
End Sub

 

 


© MESCIUS inc. All rights reserved.