Example 20 : using HTML formatting capabilitiesThe new HTML formatting capabilities in cells enable grids with complete new looks in an easy way. In this example application, the HTML formatted column headers, with images from the system image list were full defined at design time using the ColumnHeaders property. These have been set to the following values:
<IMG src="ssys:1">Column <B><FONT color="clyellow">1</FONT></B>
<IMG src="ssys:2">Column <B><FONT color="clred">2</FONT></B>
<IMG src="ssys:3">Column <B><FONT color="clblue">3</FONT></B>
<IMG src="ssys:4">Column <B><FONT color="cllime">4</FONT></B>
Further, an imagelist containing three small bitmaps has been assigned to the GridImages property. From this imagelist, the images are taken when referring to images with "idx:nr" in the HTML formatting. The normal cells have been filled with this simple loop:
with advstringgrid1 do begin for i := FixedRows to Rowcount-1 do for j := FixedCols to ColCount-1 do Cells[j,i] := '<IMG src="idx:'+inttostr((i+j) mod 3)+ '">This is <FONT color="clred">cell</FONT> <B>['+inttostr(j)+':'+inttostr(i)+']</B>'; end;
To show the capabilities of the StrippedCells property, which returns the cell string, with all HTML formatting tags removed, a handler has been assign to the MouseMove event, and the cell text is shown in the statusbar.
procedure TForm1.AdvStringGrid1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); var r,c: integer; begin Advstringgrid1.MouseToCell(x,y,c,r); if (c>=0) and (r>=0) then Statusbar1.Simpletext := Advstringgrid1.StrippedCells[c,r]; end;
To finish this small example project, the effect of the new ssHTML sorting style is shown. With this style, the sorting is done based on the cell text (with tags removed) whereas in the normal case, string comparing is performed on the full strings including the formatting. The checkbox controls which sorting style is choosen.
procedure TForm1.AdvStringGrid1GetFormat(Sender: TObject; ACol: Integer; var AStyle: TSortStyle; var aPrefix, aSuffix: String); begin if checkbox1.checked then aStyle:=ssAlphabetic else aStyle:=ssHtml; end;
Delphi project & source files for downloading included in the main demos distribution for Delphi.