How to Use Styles > Applying Styles to Cells > Applying cell styles by contents |
You can tell True DBGrid to automatically apply colors and fonts to particular cells, based upon their displayed contents. To do so, you provide a pattern, called a regular expression, which the grid tests against the displayed value of each cell. Using the AddRegexCellStyle method, you can associate a regular expression with a set of style attributes, then apply them to any possible combination of cell status values. The AddRegexCellStyle method is supported by the TDBGrid, TDBDropDown, Split, and Column objects, allowing you to control the range of cells for which certain conditions apply.
The AddRegexCellStyle method is similar to the AddCellStyle method, but it requires an additional argument for the regular expression string. As with AddCellStyle, you can use either temporary or named styles. The following example uses a temporary style to display all cells in the first column that contain the string "Windows" in bold:
Example Title |
Copy Code
|
---|---|
Dim S As New TrueDBGrid80.Style
S.Font.Bold = True
TDBGrid1.Columns(0).AddRegexCellStyle dbgAllCells, S, "Windows"
|
This feature allows you to implement "visual queries" that attach distinctive font or color attributes to cells that match a certain pattern.