MESCIUS SPREAD for Windows Forms 15.0J サンプルコード集 > 行フィルタリング > フィルタバーフィルタを有効にする |
AutoFilterModeプロパティにFilterBarを設定すると、フィルタバーフィルタが有効になります。フィルタバーにフィルタ用のセル型を割り当てることで、表示するコンテキストメニューの種類を指定します。
private void Form1_Load(object sender, EventArgs e) { // フィルターバー fpSpread1.ActiveSheet.AutoFilterMode = FarPoint.Win.Spread.AutoFilterMode.FilterBar; fpSpread1.ActiveSheet.FilterBar.Height = 50; // テキストフィルタ用のフィルタ形式 FarPoint.Win.Spread.CellType.FilterBarCellType fbtxt = new FarPoint.Win.Spread.CellType.FilterBarCellType(); fbtxt.ContextMenuType = FarPoint.Win.Spread.CellType.FilterBarContextMenuType.Text; fbtxt.ShowLabel = false; fbtxt.ShowEditor = true; fpSpread1.ActiveSheet.FilterBar.Cells[0].CellType = fbtxt; // 数値フィルタ用のフィルタ形式 FarPoint.Win.Spread.CellType.FilterBarCellType fbnum = new FarPoint.Win.Spread.CellType.FilterBarCellType(); fbnum.ContextMenuType = FarPoint.Win.Spread.CellType.FilterBarContextMenuType.Number; fbnum.ShowLabel = false; fbnum.ShowEditor = true; fpSpread1.ActiveSheet.FilterBar.Cells[1].CellType = fbnum; // 日付フィルタ用のフィルタ形式 FarPoint.Win.Spread.CellType.FilterBarCellType fbdt = new FarPoint.Win.Spread.CellType.FilterBarCellType(); fbdt.ContextMenuType = FarPoint.Win.Spread.CellType.FilterBarContextMenuType.DateTime; fbdt.ShowLabel = false; fbdt.ShowEditor = true; fpSpread1.ActiveSheet.FilterBar.Cells[2].CellType = fbdt; // カラーフィルタ用のフィルタ形式 FarPoint.Win.Spread.CellType.FilterBarCellType fbcol = new FarPoint.Win.Spread.CellType.FilterBarCellType(); fbcol.ContextMenuType = FarPoint.Win.Spread.CellType.FilterBarContextMenuType.Color; fbcol.ShowLabel = false; fbcol.ShowEditor = true; fpSpread1.ActiveSheet.FilterBar.Cells[3].CellType = fbcol; fpSpread1.ActiveSheet.Cells[0, 0].Value = "North"; fpSpread1.ActiveSheet.Cells[1, 0].Value = "South"; fpSpread1.ActiveSheet.Cells[2, 0].Value = "East"; fpSpread1.ActiveSheet.Cells[3, 0].Value = "South"; fpSpread1.ActiveSheet.Cells[4, 0].Value = "North"; fpSpread1.ActiveSheet.Cells[5, 0].Value = "North"; fpSpread1.ActiveSheet.Cells[6, 0].Value = "West"; fpSpread1.ActiveSheet.Cells[0, 1].Value = 1; fpSpread1.ActiveSheet.Cells[1, 1].Value = 2; fpSpread1.ActiveSheet.Cells[2, 1].Value = 3; fpSpread1.ActiveSheet.Cells[3, 1].Value = 4; fpSpread1.ActiveSheet.Cells[4, 1].Value = 5; fpSpread1.ActiveSheet.Cells[5, 1].Value = 6; fpSpread1.ActiveSheet.Cells[6, 1].Value = 7; fpSpread1.ActiveSheet.Cells[0, 2].Text = "2012/1/1"; fpSpread1.ActiveSheet.Cells[1, 2].Text = "2012/2/1"; fpSpread1.ActiveSheet.Cells[2, 2].Text = "2012/3/1"; fpSpread1.ActiveSheet.Cells[3, 2].Text = "2012/4/1"; fpSpread1.ActiveSheet.Cells[4, 2].Text = "2012/5/1"; fpSpread1.ActiveSheet.Cells[5, 2].Text = "2012/6/1"; fpSpread1.ActiveSheet.Cells[6, 2].Text = "2012/7/1"; fpSpread1.ActiveSheet.Cells[0, 3].BackColor = Color.Red; fpSpread1.ActiveSheet.Cells[1, 3].BackColor = Color.Blue; fpSpread1.ActiveSheet.Cells[2, 3].BackColor = Color.Green; fpSpread1.ActiveSheet.Cells[3, 3].BackColor = Color.Blue; fpSpread1.ActiveSheet.Cells[4, 3].BackColor = Color.Red; fpSpread1.ActiveSheet.Cells[5, 3].BackColor = Color.Red; fpSpread1.ActiveSheet.Cells[6, 3].BackColor = Color.Yellow; }
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load ' フィルターバー FpSpread1.ActiveSheet.AutoFilterMode = FarPoint.Win.Spread.AutoFilterMode.FilterBar FpSpread1.ActiveSheet.FilterBar.Height = 50 ' テキストフィルタ用のフィルタ形式 Dim fbtxt As New FarPoint.Win.Spread.CellType.FilterBarCellType() fbtxt.ContextMenuType = FarPoint.Win.Spread.CellType.FilterBarContextMenuType.Text fbtxt.ShowLabel = False fbtxt.ShowEditor = True FpSpread1.ActiveSheet.FilterBar.Cells(0).CellType = fbtxt ' 数値フィルタ用のフィルタ形式 Dim fbnum = New FarPoint.Win.Spread.CellType.FilterBarCellType() fbnum.ContextMenuType = FarPoint.Win.Spread.CellType.FilterBarContextMenuType.Number fbnum.ShowLabel = False fbnum.ShowEditor = True FpSpread1.ActiveSheet.FilterBar.Cells(1).CellType = fbnum ' 日付フィルタ用のフィルタ形式 Dim fbdt As New FarPoint.Win.Spread.CellType.FilterBarCellType() fbdt.ContextMenuType = FarPoint.Win.Spread.CellType.FilterBarContextMenuType.DateTime fbdt.ShowLabel = False fbdt.ShowEditor = True FpSpread1.ActiveSheet.FilterBar.Cells(2).CellType = fbdt ' カラーフィルタ用のフィルタ形式 Dim fbcol As New FarPoint.Win.Spread.CellType.FilterBarCellType() fbcol.ContextMenuType = FarPoint.Win.Spread.CellType.FilterBarContextMenuType.Color fbcol.ShowLabel = False fbcol.ShowEditor = True FpSpread1.ActiveSheet.FilterBar.Cells(3).CellType = fbcol FpSpread1.ActiveSheet.Cells(0, 0).Value = "North" FpSpread1.ActiveSheet.Cells(1, 0).Value = "South" FpSpread1.ActiveSheet.Cells(2, 0).Value = "East" FpSpread1.ActiveSheet.Cells(3, 0).Value = "South" FpSpread1.ActiveSheet.Cells(4, 0).Value = "North" FpSpread1.ActiveSheet.Cells(5, 0).Value = "North" FpSpread1.ActiveSheet.Cells(6, 0).Value = "West" FpSpread1.ActiveSheet.Cells(0, 1).Value = 1 FpSpread1.ActiveSheet.Cells(1, 1).Value = 2 FpSpread1.ActiveSheet.Cells(2, 1).Value = 3 FpSpread1.ActiveSheet.Cells(3, 1).Value = 4 FpSpread1.ActiveSheet.Cells(4, 1).Value = 5 FpSpread1.ActiveSheet.Cells(5, 1).Value = 6 FpSpread1.ActiveSheet.Cells(6, 1).Value = 7 FpSpread1.ActiveSheet.Cells(0, 2).Text = "2012/1/1" FpSpread1.ActiveSheet.Cells(1, 2).Text = "2012/2/1" FpSpread1.ActiveSheet.Cells(2, 2).Text = "2012/3/1" FpSpread1.ActiveSheet.Cells(3, 2).Text = "2012/4/1" FpSpread1.ActiveSheet.Cells(4, 2).Text = "2012/5/1" FpSpread1.ActiveSheet.Cells(5, 2).Text = "2012/6/1" FpSpread1.ActiveSheet.Cells(6, 2).Text = "2012/7/1" FpSpread1.ActiveSheet.Cells(0, 3).BackColor = Color.LightPink FpSpread1.ActiveSheet.Cells(1, 3).BackColor = Color.LightBlue FpSpread1.ActiveSheet.Cells(2, 3).BackColor = Color.LightGreen FpSpread1.ActiveSheet.Cells(3, 3).BackColor = Color.LightBlue FpSpread1.ActiveSheet.Cells(4, 3).BackColor = Color.LightPink FpSpread1.ActiveSheet.Cells(5, 3).BackColor = Color.LightPink FpSpread1.ActiveSheet.Cells(6, 3).BackColor = Color.LightYellow End Sub