フィルタ機能の実装方法
対象製品
MultiRow for Windows Forms 10.0J
詳細
フィルタリング文字列型セル(FilteringTextBoxCell)や列ヘッダ型セル(ColumnHeaderCell)を利用してフィルタ機能を実装することが可能です。
以下に実装例を紹介します。
[Visual Basic]
[C#]
以下に実装例を紹介します。
[Visual Basic]
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' テンプレートの作成 Dim template1 As Template = Template.CreateGridTemplate(2) ' HeaderDropDownContextMenuによるフィルタ機能の実装 Dim chCell1 As ColumnHeaderCell = template1.ColumnHeaders(0).Cells(0) Dim hddContextMenu1 As New HeaderDropDownContextMenu() hddContextMenu1.Items.Add(New SortToolStripItem(SortOrder.Ascending)) hddContextMenu1.Items.Add(New SortToolStripItem(SortOrder.Descending)) hddContextMenu1.Items.Add(New AutoFilterToolStripItem()) chCell1.DropDownContextMenuStrip = hddContextMenu1 ' FilteringTextBoxCellによるフィルタ機能の実装 Dim ftCell As New FilteringTextBoxCell() ftCell.Name = "ftCell" ftCell.Location = template1.ColumnHeaders(0).Cells(1).Location ftCell.Size = template1.ColumnHeaders(0).Cells(1).Size ftCell.Style.BackColor = Color.White ftCell.ComparisonType = StringComparison.CurrentCultureIgnoreCase ftCell.FilterComparisonOperator = FilterComparisonOperator.StartsWith ftCell.FilteringCellIndex = 1 template1.ColumnHeaders(0).Cells.RemoveAt(1) template1.ColumnHeaders(0).Cells.Insert(1, ftCell) template1.ColumnHeaders(0).Selectable = True template1.ColumnHeaders(0).ReadOnly = False ' MultiRowの設定 GcMultiRow1.Template = template1 GcMultiRow1.AllowUserToAddRows = False GcMultiRow1.RowCount = 10 For i As Integer = 0 To GcMultiRow1.RowCount - 1 GcMultiRow1.SetValue(i, 0, i Mod 3) GcMultiRow1.SetValue(i, 1, String.Format("B{0}", i Mod 3)) Next End Sub
[C#]
private void Form1_Load(object sender, EventArgs e) { // テンプレートの作成 Template template1 = Template.CreateGridTemplate(2); // HeaderDropDownContextMenuによるフィルタ機能の実装 ColumnHeaderCell chCell1 = (ColumnHeaderCell)template1.ColumnHeaders[0].Cells[0]; HeaderDropDownContextMenu hddContextMenu1 = new HeaderDropDownContextMenu(); hddContextMenu1.Items.Add(new SortToolStripItem(SortOrder.Ascending)); hddContextMenu1.Items.Add(new SortToolStripItem(SortOrder.Descending)); hddContextMenu1.Items.Add(new AutoFilterToolStripItem()); chCell1.DropDownContextMenuStrip = hddContextMenu1; // FilteringTextBoxCellによるフィルタ機能の実装 FilteringTextBoxCell ftCell = new FilteringTextBoxCell(); ftCell.Name = "ftCell"; ftCell.Location = template1.ColumnHeaders[0].Cells[1].Location; ftCell.Size = template1.ColumnHeaders[0].Cells[1].Size; ftCell.Style.BackColor = System.Drawing.Color.White; ftCell.ComparisonType = StringComparison.CurrentCultureIgnoreCase; ftCell.FilterComparisonOperator = FilterComparisonOperator.StartsWith; ftCell.FilteringCellIndex = 1; template1.ColumnHeaders[0].Cells.RemoveAt(1); template1.ColumnHeaders[0].Cells.Insert(1, ftCell); template1.ColumnHeaders[0].Selectable = true; template1.ColumnHeaders[0].ReadOnly = false; // MultiRowの設定 gcMultiRow1.Template = template1; gcMultiRow1.AllowUserToAddRows = false; gcMultiRow1.RowCount = 10; for(int i = 0; i < gcMultiRow1.RowCount; i++) { gcMultiRow1.SetValue(i, 0, i % 3); gcMultiRow1.SetValue(i, 1, string.Format("B{0}", i % 3)); } }