# Search Row

**RadGridView** offers a build-in search functionality available for both end users and developers. The search mechanism executes in a separate thread which leaves the UI responsive at all times. To enable the search row for end users all you have to do is set the **AllowSearchRow** property of **RadGridView** to *true*:

```C#
this.radGridView1.AllowSearchRow = true;
```

```VB.NET
Me.RadGridView1.AllowSearchRow = True
```

![WinForms RadGridView Search Row](https://www.telerik.com/products/winforms/documentation/assets/2d0f912b87ee41c7ba1cf5d954b54a83/gridview-rows-search-row001.png)

> note As of **R2 2019 SP** **GridViewSearchRowInfo** offers the **DeferredSearch** property which indicates whether the grid control will wait until the `Enter` key is pressed before a new search operation is started. Its default value is *false*.

The end user can select in which columns to perform searching by the provided *Search in columns* drop down. Thus, the highlighted result will be displayed in the specified columns only. You can specify whether the search functionality is enabled for a given column by setting the column's **AllowSearching** property.

![WinForms RadGridView Search in columns drop down](https://www.telerik.com/products/winforms/documentation/assets/cee0ea5f8217ee582797c007aca08878/gridview-rows-search-row002.png)

> important Since **R2 2018 SP1** RadGridView has a property **IsSearchAsync** which controls whether the search will be performed on a background thread \[*true*] or on the main thread \[*false*].

### Properties

The available properties to tweak the search experience and performance and how to access them are outlined below. The API is in the **GridViewSearchRowInfo** object which can be accessed through the grid view **MasterView**.

| Property                           | Description                                                                                                                                                                                                   |
| ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **CaseSensitive**                  | This property defines whether searching will be case sensitive or case insensitive.                                                                                                                           |
| **Culture**                        | The culture which [CompareInfo](http://msdn.microsoft.com/en-us/library/System.Globalization.CompareInfo.IndexOf\(v=vs.110\).aspx) object will be used for searches when **CaseSensitive** is set to *false*. |
| **CompareOptions**                 | A **CompareOptions** value that defines how search will be performed when **CaseSensitive** is set to *false*.                                                                                                |
| **HighlightResults**               | Determines whether results will be highlighted with cells.                                                                                                                                                    |
| **AutomaticallySelectFirstResult** | Determines if the first result found by the search mechanism will be selected and brought into view.                                                                                                          |
| **ShowClearButton**                | Gets or sets a value indicating whether to show the clear button.                                                                                                                                             |
| **ShowCloseButton**                | Gets or sets a value indicating whether to show the close button.                                                                                                                                             |
| **CloseOnEscape**                  | Gets or sets a value indicating whether to close the search row when escape key is pressed.                                                                                                                   |
| **IsSearchAsync**                  | Gets or sets a value indicating whether the search will be performed on a background thread \[true] or on the main thread \[false].                                                                           |
| **SearchDelay**                    | Gets or sets a value indicating how long the grid will wait after a key is pressed until it starts a search.                                                                                                  |
| **DeferredSearch**                 | Gets or sets a value indicating whether grid will wait until Enter key is pressed before it starts a search.                                                                                                  |

> note Pressing `Ctrl`+`F` will show the search row if it is hidden. The `Esc` key will close the search row.

> note The **ContextMenuOpening** event is fired when the settings drop down is about to be shown. The ContextMenuOpeningEventArgs.**ContextMenuProvider** is the **GridSearchCellElement** in this case.

To change the highlight color you should use the **HighlightColor** property of the TableElement.

```C#
radGridView1.TableElement.SearchHighlightColor = Color.LightBlue;
```

```VB.NET
RadGridView1.TableElement.SearchHighlightColor = Color.LightBlue
```

You can also use the search functionality programmatically without showing the search row, just by using its API.

```C#
GridViewSearchRowInfo searchRow = this.radGridView1.MasterView.TableSearchRow;
```

```VB.NET
Dim searchRow As GridViewSearchRowInfo = Me.RadGridView1.MasterView.TableSearchRow
```

To manually search, call the **Search** method and pass the search criteria as a parameter. To get the search results you have to subscribe to the **SearchProgressChanged** event. In the event handler you will have to handle three cases:

1. Initially the search results are returned one at a time. This allows you to quickly get the first results as they are discovered. In this case the **Cell** property of the **SearchProgressChangedEventArgs** will contain the cell that was found. You can control how many results are returned one by one through the **InitialSearchResultsTreshold** property of the search row. If you set the property to 0 you will skip this case entirely.

2. After the threshold is reached results are returned in groups of cells. This improves performance as less calls are required from the search thread to the main thread. In this case the **Cells** property of **SearchProgressChangedEventArgs** will contain a collection of cells that matched the search criteria. To control the size of the **Cells** collection you can use the **SearchResultsGroupSize** property of the search row. If the **InitialSearchResultsTreshold** is greater than the total search results you might not fall in this case. If the search cache already contains the results for a given search criteria this cache will be return as a collection right away.

3. The search is complete. In this case the **SearchFinished** property will return *true*.

In (Table 1.) you can see an overview of the values of the properties in the above cases.

**Table 1.**

|                                | **Cell**                 | **Cells**                      | **Search finished** |
| ------------------------------ | ------------------------ | ------------------------------ | ------------------- |
| **Until threshold is reached** | GridSearchResultCellInfo | null                           | false               |
| **After threshold is reached** | null                     | GridSearchResultCellCollection | false               |
| **Search end**                 | null                     | null                           | true                |

The search mechanism of **RadGridView** searches in group rows as well as data rows. Since there are no cells respectively columns in group rows the **ColumnInfo** property of the **GridSearchResultCellInfo** will be `null` for group rows.

If you start a search operation before a previous one is complete the old one will be stopped and the new one will be started immediately. If a search operation successfully finishes the results from it are cached for subsequent searches.

## Suspend the search operation

You can suspend/resume the search temporarily by using the **SuspendSearch** and **ResumeSearch** methods. The **IsSearchSuspended** indicates if the search is currently suspended.

### Suspend the search operation

```C#
radGridView1.MasterView.TableSearchRow.SuspendSearch();

radGridView1.MasterView.TableSearchRow.ResumeSearch();
```

```VB.NET
RadGridView1.MasterView.TableSearchRow.SuspendSearch()

RadGridView1.MasterView.TableSearchRow.ResumeSearch()
```

## See Also

* [StartsWith search in RadGridView](https://www.telerik.com/products/winforms/documentation/knowledge-base/starts-with-search-in-radgridview)

* [How to Properly Search Numeric Values in RadGridView](https://www.telerik.com/products/winforms/documentation/knowledge-base/grid-searching-in-formated-decimal-columns)

* [Adding and Inserting Rows](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/adding-and-inserting-rows)

* [Conditional Formatting Rows](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/conditional-formatting-rows)

* [Creating custom rows](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/creating-custom-rows)

* [Drag and Drop](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/drag-and-drop)

* [Formatting Rows](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/formatting-rows)

* [GridViewRowInfo](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/gridviewrowinfo)

* [Iterating Rows](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/iterating-rows)

* [New Row](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/new-row)
