How to Properly Search Numeric Values in RadGridView
Environment
Product Version | Product | Author |
---|---|---|
2022.2.622 | RadGridView for WinForms | Desislava Yordanova |
Description
The Digit grouping symbol is specified in the Regional settings of the local machine, e.g. ",":
However, it is possible to specify the Culture at application level and set another NumberGroupSeparator, e.g. " ":
Thus, if you specify the GridViewDecimalColumn.FormatString property to N2, the numeric cell values will be formatted according to the application's culture - there is a space as a number group separator:
Once the user starts typing, the search functionality doesn't consider the NumberGroupSeparator:
Type raw value | Type formatted value |
---|---|
![]() |
![]() |
This tutorial demonstrates the different approaches that can be followed to achieve proper search functionality in formatted decimal columns in RadGridView.
Solution
When a specific Culture is applied to the application, note that the formatted GridViewDecimalColumn uses by default the regional settings of the local machine when performing the search operation. That is why it is necessary to specify this Culture to the column itself via the FormatInfo property:
Note that the search functionality in RadGridView is purposed to search for the matches considering the formatted cells' values /not the raw cell's value/ according to the applied culture to the column. The formatted text is actually highlighted then. That is why it is required to enter the NumberGroupSeparator when searching in order to find an exact match, e.g. "461 8".
If you want to handle both cases , entering "461 8" and "4618", the search functionality is not appropriate as it is expected to highlight the exact text match.
The appropriate way in this case is to use the custom filtering functionality. Thus, you have full control over what rows to be visible or not according to the raw value.
Add a RadTextBox control above the grid and use it for the user's input:
Search Results and Highlighted Cells
The search functionality is designed to highlight the formatted text as it highlights the precise characters that match the search criteria.
Another possible solution is to disable the highlighting and implement your own custom search logic. Then, the CellFormatting event will be used to highlight the cells that contain search matches:
It is important to subscribe to the CreateRowInfo event at design time.