FlexGrid for WinForms
検索

FlexGrid を使用すると、グリッド全体、または特定の列のみを対象とした検索を簡単に実行できます。このトピックでは、FlexGrid で検索を行う方法について説明します。

グリッド全体の検索

FlexGrid 全体を検索するには、C1FlexGridSearchPanel コントロールをフォームに追加し、SetC1FlexGridSearchPanel メソッドを使用して検索対象のグリッドと関連付ける必要があります。C1FlexGridSearchPanel コントロールは、検索結果を強調表示し、検索結果が含まれるレコードを自動的にフィルタ処理します。ただし、HighlightSearchResultsfalse に設定することで、結果を強調表示しないようにすることもできます。また、検索を自動的に開始するか、[検索]ボタンまたは[Enter]キーが押されたときに開始するかを設定する SearchMode プロパティも提供されています。検索ボックス内のウォーターマークや、検索の遅延時間を設定することもできます。

グリッド全体の検索

SearchPanel を使用して WinForms FlexGrid 全体を検索するには、次のコードを使用します。

// 検索パネルを検索対象のFlexGridに関連付けます。
c1FlexGridSearchPanel1.SetC1FlexGridSearchPanel(c1FlexGrid1, c1FlexGridSearchPanel1);
// 検索を構成します
c1FlexGridSearchPanel1.HighlightSearchResults = true;
c1FlexGridSearchPanel1.SearchMode = C1.Win.C1FlexGrid.SearchMode.Always;
c1FlexGridSearchPanel1.Watermark = "Search products";
c1FlexGridSearchPanel1.SearchDelay = 2;  
' 検索パネルを検索対象のFlexGridに関連付けます。
c1FlexGridSearchPanel1.SetC1FlexGridSearchPanel(c1FlexGrid1, c1FlexGridSearchPanel1)
' 検索を構成します
c1FlexGridSearchPanel1.HighlightSearchResults = True
c1FlexGridSearchPanel1.SearchMode = C1.Win.C1FlexGrid.SearchMode.Always
c1FlexGridSearchPanel1.Watermark = "Search products"
c1FlexGridSearchPanel1.SearchDelay = 2

Besides an in-built search panel, you can use ApplySearch method of the C1FlexGrid class to search data in the entire grid. The ApplySearch() method provides various overloads to perform search in FlexGrid as listed below:

Overload Description
ApplySearch(string search, SearchHighlightMode highlightMode) Applies search to the data on the grid depending on how the highlight mode has defined search result to be highlighted.
ApplySearch(string search, SearchHighlightMode highlightMode, bool filter) Applies search to the data on the grid depending on how the highlight mode has defined search result to be highlighted and also defines if search result is filtered or not.
ApplySearch(string search, SearchHighlightMode highlightMode, bool filter, bool onlyVisibleColumns) Applies search to the data on the grid depending on how the highlight mode has defined search result to be highlightedand also defines if search result is filtered or not. Additionally, this overload lets you apply search on only visible columns in the grid.
ApplySearch(string search, SearchHighlightMode highlightMode, bool filter, bool onlyVisibleColumns, bool onlyVisibleRows) Applies search to the data on the grid depending on how the highlight mode has defined search result to be highlightedand also defines if search result is filtered or not. Additionally, this overload lets you apply search on only visible rows and columns in the grid.

To apply search in FlexGrid using the ApplySearch() method, use the following code. This code searches for the occurrence of the word "Car" and highlights only the first search result. This example uses the sample created in Quick Start.

C#
コードのコピー
c1FlexGrid1.ApplySearch("Car", SearchHighlightMode.OnlyFirst);

列内の検索

列方向の検索を可能にするために、FlexGrid には、AutoSearchEnum 列挙の値を受け取る C1FlexGrid クラスの AutoSearch プロパティが用意されています。この列挙を使用して、スクロール可能な最初の行、または現在のカーソル位置から下方向への列検索を開始できます。特定の列で値を検索するには、カーソルをその列内に置き、検索する値を入力します。これで、グリッドは、その列内の検索結果に自動的にジャンプします。AutoSearchDelay プロパティを設定して、検索の遅延を設定することもできます。

列内の検索

次のコードは、WinForms FlexGrid で列方向の検索を可能にします。

// 一番上の行からの列単位の検索を有効にします 
c1FlexGrid1.AutoSearch = C1.Win.C1FlexGrid.AutoSearchEnum.FromTop;
c1FlexGrid1.AutoSearchDelay = 2;        
' 一番上の行からの列単位の検索を有効にします 
c1FlexGrid1.AutoSearch = C1.Win.C1FlexGrid.AutoSearchEnum.FromTop
c1FlexGrid1.AutoSearchDelay = 2      
関連トピック