PowerTools MultiRow for Windows Forms 8.0J
FilteringTextBoxCell クラス
メンバ  使用例 

すべてのRowの指定したCellを、指定した条件に従ってフィルタリングする、特別なTextBoxCellを表します。
構文
Public Class FilteringTextBoxCell 
   Inherits TextBoxCell
   Implements IFilteringCell 
public class FilteringTextBoxCell : TextBoxCell, IFilteringCell  
解説
ColumnHeaderSectionまたはColumnFooterSectionFilteringTextBoxCellを追加し、FilteringCellIndexまたはFilteringCellNameによって行のフィルタリングに使用するセルを指定した後、フィルタリング条件を示すFilterComparisonOperatorを指定します。フィルタリング操作をカスタマイズする場合は、FilterComparisonOperatorプロパティをFilterComparisonOperator.Customに設定し、System.Collections.IComparerを実装してCustomComparisonOperatorに設定します。
使用例
次のサンプルコードは、フィルタリングテキストボックス型セルを使用してフィルタ操作を実行する方法と、このセルのプロパティをカスタマイズする方法を示します。
using System;
using System.Drawing;
using System.Windows.Forms;

namespace GrapeCity.Win.MultiRow.SampleCode
{
    public class FilteringTextBoxCellDemo : Form
    {
        private GcMultiRow gcMultiRow1 = new GcMultiRow();

        private Label descriptionLable = new Label();

        public FilteringTextBoxCellDemo()
        {
            this.Text = "FilteringTextBoxCell Demo";
            this.Size = new Size(350, 400);

            // Add MultiRow to form
            this.gcMultiRow1.Dock = DockStyle.Fill;
            this.Controls.Add(this.gcMultiRow1);

            descriptionLable.Height = 40;
            descriptionLable.BackColor = SystemColors.Info;
            descriptionLable.Dock = DockStyle.Bottom;
            descriptionLable.Text = "Edit values of cells in the Yellow section to perform filter";
            this.Controls.Add(descriptionLable);

            this.Load += new EventHandler(Form1_Load);

            gcMultiRow1.CellValueChanged += new EventHandler<CellEventArgs>(gcMultiRow1_CellValueChanged);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            TextBoxCell nameTextBoxCell = new TextBoxCell();
            TextBoxCell departmentTextBoxCell = new TextBoxCell();
            CheckBoxCell genderCheckBoxCell = new CheckBoxCell();

            Cell[] comboBoxCells = new Cell[] { nameTextBoxCell, departmentTextBoxCell, genderCheckBoxCell };

            Template template1 = Template.CreateGridTemplate(comboBoxCells);

            ColumnHeaderSection filterRow = new ColumnHeaderSection();
            filterRow.Height = 21;

            // Filter row should can be edited.
            filterRow.ReadOnly = false;
            filterRow.Selectable = true;
            filterRow.BackColor = Color.Yellow;

            filterRow.Cells.Add(CreateTextFilterCell());
            filterRow.Cells.Add(CreateComboBoxFilterCell());
            filterRow.Cells.Add(CreateCheckBoxFilterCell());

            filterRow.Cells[0].Location = nameTextBoxCell.Location;
            filterRow.Cells[1].Location = departmentTextBoxCell.Location;
            filterRow.Cells[2].Location = genderCheckBoxCell.Location;

            template1.ColumnHeaders.Add(filterRow);

            gcMultiRow1.Template = template1;

            this.gcMultiRow1.ColumnHeaders[0][0].Value = "Name";
            this.gcMultiRow1.ColumnHeaders[0][1].Value = "Department";
            this.gcMultiRow1.ColumnHeaders[0][2].Value = "Gender";

            this.FillData();
        }

        private Cell CreateTextFilterCell()
        {
            FilteringTextBoxCell filteringTextBoxCell = new FilteringTextBoxCell();

            filteringTextBoxCell.FilteringCellIndex = 0;
            filteringTextBoxCell.ComparisonType = StringComparison.InvariantCultureIgnoreCase;
            filteringTextBoxCell.FilterComparisonOperator = FilterComparisonOperator.StartsWith;

            return filteringTextBoxCell;
        }

        private Cell CreateComboBoxFilterCell()
        {
            return new MyFileringComboBoxCell();
        }

        class MyFileringComboBoxCell : ComboBoxCell, IFilteringCell
        {
            public MyFileringComboBoxCell()
            {
                this.Items.Add("");
                this.Items.Add("Leader");
                this.Items.Add("Developer");
                this.Items.Add("Tester");
            }

            public bool Filtering(object editedFormattedValue, object targetCellValue, int targetRowIndex)
            {
                if (object.Equals(editedFormattedValue, string.Empty) || object.Equals(editedFormattedValue, null))
                {
                    return false;
                }
                return !object.Equals(editedFormattedValue, targetCellValue);
            }

            public int FilteringCellIndex
            {
                get { return 1; }
            }
        }

        private Cell CreateCheckBoxFilterCell()
        {
            return new MyFilteringCheckBoxCell();
        }

        class MyFilteringCheckBoxCell : CheckBoxCell, IFilteringCell
        {
            public MyFilteringCheckBoxCell()
            {
                this.ThreeState = true;
            }

            public bool Filtering(object editedFormattedValue, object targetCellValue, int targetRowIndex)
            {
                if (object.Equals(editedFormattedValue, CheckState.Indeterminate))
                {
                    return false;
                }
                if (object.Equals(targetCellValue, null) || object.Equals(targetCellValue, false))
                {
                    return !object.Equals(editedFormattedValue, CheckState.Unchecked);
                }
                if (object.Equals(targetCellValue, true))
                {
                    return !object.Equals(editedFormattedValue, CheckState.Checked);
                }
                return false;
            }

            public int FilteringCellIndex
            {
                get { return 2; }
            }
        }

        void gcMultiRow1_CellValueChanged(object sender, CellEventArgs e)
        {
            // After user edit, the new value of the cell may should be hidden.
            // Call UpdateFiltering can Perform filter base on newest value.
            if (e.Scope == CellScope.Row && e.CellIndex == 0)
            {
                this.gcMultiRow1.UpdateFiltering();
            }
        }

        private void FillData()
        {
            this.gcMultiRow1.Rows.Add("Wedy", "Developer", true);
            this.gcMultiRow1.Rows.Add("Walter", "Developer", true);
            this.gcMultiRow1.Rows.Add("Robert", "Developer", true);
            this.gcMultiRow1.Rows.Add("Colin", "Leader", true);
            this.gcMultiRow1.Rows.Add("Erwin", "Developer", true);
            this.gcMultiRow1.Rows.Add("Alice", "Tester", false);
            this.gcMultiRow1.Rows.Add("Gina", "Tester", false);
            this.gcMultiRow1.Rows.Add("Mark", "Leader", true);
            this.gcMultiRow1.Rows.Add("Robbie", "Tester", true);
        }

        [STAThreadAttribute()]
        public static void Main()
        {
            Application.EnableVisualStyles();
            Application.Run(new FilteringTextBoxCellDemo());
        }
    }
}
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports GrapeCity.Win.MultiRow

Public Class FilteringTextBoxCellDemo
    Inherits Form
    Friend WithEvents gcMultiRow1 As New GcMultiRow()

    Private descriptionLable As New Label()

    Public Sub New()
        Me.Text = "FilteringTextBoxCell Demo"
        Me.Size = New Size(350, 400)

        ' Add MultiRow to form
        Me.gcMultiRow1.Dock = DockStyle.Fill
        Me.Controls.Add(Me.gcMultiRow1)

        descriptionLable.Height = 40
        descriptionLable.BackColor = SystemColors.Info
        descriptionLable.Dock = DockStyle.Bottom
        descriptionLable.Text = "Edit values of cells in the Yellow section to perform filter"
        Me.Controls.Add(descriptionLable)
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Dim nameTextBoxCell As New TextBoxCell()
        Dim departmentTextBoxCell As New TextBoxCell()
        Dim genderCheckBoxCell As New CheckBoxCell()

        Dim comboBoxCells As Cell() = New Cell() {nameTextBoxCell, departmentTextBoxCell, genderCheckBoxCell}

        Dim template1 As Template = Template.CreateGridTemplate(comboBoxCells)

        Dim filterRow As New ColumnHeaderSection()
        filterRow.Height = 21

        ' Filter row should can be edited.
        filterRow.ReadOnly = False
        filterRow.Selectable = True
        filterRow.BackColor = Color.Yellow

        filterRow.Cells.Add(CreateTextFilterCell())
        filterRow.Cells.Add(CreateComboBoxFilterCell())
        filterRow.Cells.Add(CreateCheckBoxFilterCell())

        filterRow.Cells(0).Location = nameTextBoxCell.Location
        filterRow.Cells(1).Location = departmentTextBoxCell.Location
        filterRow.Cells(2).Location = genderCheckBoxCell.Location

        template1.ColumnHeaders.Add(filterRow)

        gcMultiRow1.Template = template1

        Me.gcMultiRow1.ColumnHeaders(0)(0).Value = "Name"
        Me.gcMultiRow1.ColumnHeaders(0)(1).Value = "Department"
        Me.gcMultiRow1.ColumnHeaders(0)(2).Value = "Gender"

        Me.FillData()
    End Sub

    Private Function CreateTextFilterCell() As Cell
        Dim filteringTextBoxCell As New FilteringTextBoxCell()

        filteringTextBoxCell.FilteringCellIndex = 0
        filteringTextBoxCell.ComparisonType = StringComparison.InvariantCultureIgnoreCase
        filteringTextBoxCell.FilterComparisonOperator = FilterComparisonOperator.StartsWith

        Return filteringTextBoxCell
    End Function

    Private Function CreateComboBoxFilterCell() As Cell
        Return New MyFileringComboBoxCell()
    End Function

    Private Class MyFileringComboBoxCell
        Inherits ComboBoxCell
        Implements IFilteringCell
        Public Sub New()
            Me.Items.Add("")
            Me.Items.Add("Leader")
            Me.Items.Add("Developer")
            Me.Items.Add("Tester")
        End Sub

        Public Function Filtering(ByVal editedFormattedValue As Object, ByVal targetCellValue As Object, ByVal targetRowIndex As Integer) As Boolean Implements IFilteringCell.Filtering
            If Object.Equals(editedFormattedValue, String.Empty) OrElse Object.Equals(editedFormattedValue, Nothing) Then
                Return False
            End If
            Return Not Object.Equals(editedFormattedValue, targetCellValue)
        End Function

        Public ReadOnly Property FilteringCellIndex() As Integer Implements IFilteringCell.FilteringCellIndex
            Get
                Return 1
            End Get
        End Property
    End Class

    Private Function CreateCheckBoxFilterCell() As Cell
        Return New MyFilteringCheckBoxCell()
    End Function

    Private Class MyFilteringCheckBoxCell
        Inherits CheckBoxCell
        Implements IFilteringCell
        Public Sub New()
            Me.ThreeState = True
        End Sub

        Public Function Filtering(ByVal editedFormattedValue As Object, ByVal targetCellValue As Object, ByVal targetRowIndex As Integer) As Boolean Implements IFilteringCell.Filtering
            If Object.Equals(editedFormattedValue, CheckState.Indeterminate) Then
                Return False
            End If
            If Object.Equals(targetCellValue, Nothing) OrElse Object.Equals(targetCellValue, False) Then
                Return Not Object.Equals(editedFormattedValue, CheckState.Unchecked)
            End If
            If Object.Equals(targetCellValue, True) Then
                Return Not Object.Equals(editedFormattedValue, CheckState.Checked)
            End If
            Return False
        End Function

        Public ReadOnly Property FilteringCellIndex() As Integer Implements IFilteringCell.FilteringCellIndex
            Get
                Return 2
            End Get
        End Property
    End Class

    Private Sub gcMultiRow1_CellValueChanged(ByVal sender As Object, ByVal e As CellEventArgs) Handles gcMultiRow1.CellValueChanged
        ' After user edit, the new value of the cell may should be hidden.
        ' Call UpdateFiltering can Perform filter base on newest value.
        If e.Scope = CellScope.Row AndAlso e.CellIndex = 0 Then
            Me.gcMultiRow1.UpdateFiltering()
        End If
    End Sub

    Private Sub FillData()
        Me.gcMultiRow1.Rows.Add("Wedy", "Developer", True)
        Me.gcMultiRow1.Rows.Add("Walter", "Developer", True)
        Me.gcMultiRow1.Rows.Add("Robert", "Developer", True)
        Me.gcMultiRow1.Rows.Add("Colin", "Leader", True)
        Me.gcMultiRow1.Rows.Add("Erwin", "Developer", True)
        Me.gcMultiRow1.Rows.Add("Alice", "Tester", False)
        Me.gcMultiRow1.Rows.Add("Gina", "Tester", False)
        Me.gcMultiRow1.Rows.Add("Mark", "Leader", True)
        Me.gcMultiRow1.Rows.Add("Robbie", "Tester", True)
    End Sub

    <STAThreadAttribute()> _
    Public Shared Sub Main()
        Application.EnableVisualStyles()
        Application.Run(New FilteringTextBoxCellDemo())
    End Sub
End Class
継承階層

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         GrapeCity.Win.MultiRow.Cell
            GrapeCity.Win.MultiRow.TextBoxCell
               GrapeCity.Win.MultiRow.FilteringTextBoxCell

参照

FilteringTextBoxCell メンバ
GrapeCity.Win.MultiRow 名前空間
Cell クラス
TextBoxCell クラス

 

 


© 2008-2015 GrapeCity inc. All rights reserved.