PowerTools MultiRow for Windows Forms 8.0J
SearchNextCellPositionNeeded イベント
使用例 

検索中に次の検索位置が必要になると発生します。
構文
Public Event SearchNextCellPositionNeeded As EventHandler(Of SearchNextCellPositionNeededEventArgs)
public event EventHandler<SearchNextCellPositionNeededEventArgs> SearchNextCellPositionNeeded
イベント データ

イベント ハンドラが、このイベントに関連するデータを含む、SearchNextCellPositionNeededEventArgs 型の引数を受け取りました。次の SearchNextCellPositionNeededEventArgs プロパティには、このイベントの固有の情報が記載されます。

プロパティ解説
CurrentCellPosition現在のセルの位置を取得します。  
Handled System.ComponentModel.HandledEventArgsから継承されます。
NextCellPosition次の検索位置を取得または設定します。  
SearchOrder検索順序を取得します。  
TerminateSearch検索を終了するかどうかを示す値を取得または設定します。  
使用例
次のサンプルコードは、検索中に検索順序をカスタマイズする方法を示します。
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GrapeCity.Win.MultiRow.SampleCode
{
    public class QuickSearchDemo : Form
    {
        private GcMultiRow gcMuliRow1 = new GcMultiRow();
        private CellPosition currentCellPosition = CellPosition.Empty;
        private CellPosition endCellPosition = new CellPosition(3, 3);

        public QuickSearchDemo()
        {
            this.Text = "QuickSearch Demo";
            this.Size = new System.Drawing.Size(800, 400);
            this.StartPosition = FormStartPosition.CenterScreen;

            this.gcMuliRow1.Dock = DockStyle.Fill;
            this.Controls.Add(this.gcMuliRow1);
            this.Load += QuickSearchDemoLoad;
        }

        private void QuickSearchDemoLoad(object sender, EventArgs e)
        {            
            Template template = Template.Default;
            template.Row.Cells[0].Value = "a";
            template.Row.Cells[1].Value = "a";
            template.Row.Cells[2].Value = "a";
            template.Row.Cells[3].Value = "a";
            this.gcMuliRow1.Template = template;
            this.gcMuliRow1.RowCount = 20;
            this.gcMuliRow1.SearchNextCellPositionNeeded += gcMuliRow1_SearchNextCellPositionNeeded;
            this.gcMuliRow1.ShortcutKeyManager.DefaultModeList.Add(new ShortcutKey(EditingActions.SearchAction, Keys.Control | Keys.F));     
        }

        private void gcMuliRow1_SearchNextCellPositionNeeded(object sender, SearchNextCellPositionNeededEventArgs e)
        {
            currentCellPosition = e.CurrentCellPosition;
            int currentRowIndex = currentCellPosition.RowIndex;
            int currentCellIndex = currentCellPosition.CellIndex;

            if (e.SearchOrder == SearchOrder.NOrder)
            {
                if (currentCellIndex == 0)
                {
                    currentCellIndex = 2;
                }
                else if (currentCellIndex == 1)
                {
                    currentCellIndex = 3;
                }
                else if (currentCellIndex == 2)
                {
                    currentRowIndex++;
                    currentCellIndex = 0;
                }
                else if (currentCellIndex == 3)
                {
                    currentRowIndex++;
                    currentCellIndex = 1;
                }

                //if next cell is out of range,jump to other cell.
                if (currentRowIndex == endCellPosition.RowIndex + 1
                && currentCellIndex == 0)
                {
                    currentRowIndex = 0;
                    currentCellIndex = 1;
                }

                //terminate search
                if (currentRowIndex == endCellPosition.RowIndex
                    && currentCellIndex == endCellPosition.CellIndex)
                {
                    e.TerminateSearch = true;
                }

                //set nexcell position
                e.NextCellPosition = new CellPosition(currentRowIndex, currentCellIndex);

                //Handled is true indicates customer handel search action.
                e.Handled = true;
            }
        }

        [STAThreadAttribute()]
        public static void Main()
        {
            Application.EnableVisualStyles();
            Application.Run(new QuickSearchDemo());
        }
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms

Namespace GrapeCity.Win.MultiRow.SampleCode

    Public Class QuickSearchDemo
        Inherits Form
        Private gcMuliRow1 As GcMultiRow = New GcMultiRow()

        Private currentCellPosition As CellPosition = CellPosition.Empty
        Private endCellPosition As CellPosition = New CellPosition(3, 3)

        Public Sub New()
            MyBase.New()
            Me.Text = "QuickSearch Demo"
            Me.Size = New System.Drawing.Size(800, 400)
            Me.StartPosition = FormStartPosition.CenterScreen
            Me.gcMuliRow1.Dock = DockStyle.Fill
            Me.Controls.Add(Me.gcMuliRow1)
            AddHandler gcMuliRow1.SearchNextCellPositionNeeded, AddressOf gcMuliRow1_SearchNextCellPositionNeeded
        End Sub

        Private Sub QuickSearchDemoLoad(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load            
            Dim template As Template = template.Default
            template.Row.Cells(0).Value = "a"
            template.Row.Cells(1).Value = "a"
            template.Row.Cells(2).Value = "a"
            template.Row.Cells(3).Value = "a"
            Me.gcMuliRow1.Template = template
            Me.gcMuliRow1.RowCount = 20
            Me.gcMuliRow1.ShortcutKeyManager.DefaultModeList.Add(New ShortcutKey(EditingActions.SearchAction, (Keys.Control Or Keys.F)))
        End Sub

        Private Sub gcMuliRow1_SearchNextCellPositionNeeded(ByVal sender As Object, ByVal e As SearchNextCellPositionNeededEventArgs)

            currentCellPosition = e.CurrentCellPosition
            Dim currentRowIndex As Integer = currentCellPosition.RowIndex
            Dim currentCellIndex As Integer = currentCellPosition.CellIndex
            If (e.SearchOrder = SearchOrder.NOrder) Then
                If (currentCellIndex = 0) Then
                    currentCellIndex = 2
                ElseIf (currentCellIndex = 1) Then
                    currentCellIndex = 3
                ElseIf (currentCellIndex = 2) Then
                    currentRowIndex = (currentRowIndex + 1)
                    currentCellIndex = 0
                ElseIf (currentCellIndex = 3) Then
                    currentRowIndex = (currentRowIndex + 1)
                    currentCellIndex = 1
                End If
                'if next cell is out of range,jump to other cell.
                If ((currentRowIndex _
                            = (endCellPosition.RowIndex + 1)) _
                            AndAlso (currentCellIndex = 0)) Then
                    currentRowIndex = 0
                    currentCellIndex = 1
                End If
                'terminate search
                If ((currentRowIndex = endCellPosition.RowIndex) _
                            AndAlso (currentCellIndex = endCellPosition.CellIndex)) Then
                    e.TerminateSearch = True
                End If
                'set nexcell position
                e.NextCellPosition = New CellPosition(currentRowIndex, currentCellIndex)
                'Handled is true indicates customer handel search action.
                e.Handled = True
            End If
        End Sub

        <STAThreadAttribute()> _
        Public Shared Sub Main()
            Application.EnableVisualStyles()
            Application.Run(New QuickSearchDemo)
        End Sub
    End Class
End Namespace
参照

GcMultiRow クラス
GcMultiRow メンバ

 

 


© 2008-2015 GrapeCity inc. All rights reserved.