ComponentOne True DBGrid for .NET (2.0) Search HelpCentral 

Applying Cell Styles by Contents

True DBGrid can automatically apply colors and fonts to particular cells, based upon their displayed contents. To do so, provide a pattern, called a regular expression that the grid tests against the displayed value of each cell. Using the AddRegexCellStyle method, associate a regular expression with a set of style attributes, and then apply them to any possible combination of cell status values. The AddRegexCellStyle method is supported by the C1TrueDBGrid, C1TrueDBDropDown, Split, and C1DisplayColumn objects, allowing the range of cells for which certain conditions apply to be controlled.

The AddRegexCellStyle method is similar to the AddCellStyle method, but it requires an additional argument for the regular expression string. As with AddCellStyle, 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:

·      Visual Basic

Dim S As New C1.Win.C1TrueDBGrid.Style()

Dim myfont As Font

 

myfont = New Font(S.Font, FontStyle.Bold)

S.Font = myfont

Me.C1TrueDBGrid1.AddRegexCellStyle (C1.Win.C1TrueDBGrid.CellStyleFlag.AllCells, S, "Computer")

·      C#

C1TrueDBGrid.Style  S = new C1.Win.C1TrueDBGrid.Style();

Font myfont;

 

myfont = new Font(S.Font, FontStyle.Bold);

S.Font = myfont;

this.c1TrueDBGrid1.AddRegexCellStyle (C1.Win.C1TrueDBGrid.CellStyleFlag.AllCells, S, "Computer");

·      Delphi

var S: C1.Win.C1TrueDBGrid.Style;

    myfont: Font;

 

S := C1.Win.C1TrueDBGrid.Style.Create;

myfont := Font.Create(S.Font, FontStyle.Bold);

S.Font := myfont;

Self.C1TrueDBGrid1.AddRegexCellStyle(C1.Win.C1TrueDBGrid.CellStyleFlag.AllCells, S,'Windows');

This feature allows the implementation of "visual queries" that attach distinctive font or color attributes to cells that match a certain pattern.


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.