PRODUCTS

FEATURED PRODUCT

The most powerful, fastest & flexible suite for native Excel file manipulation and Excel,PDF,HTML report generation for .NET

License only 125 EUR See More

SEARCH

LOGIN

Customer login to access products, support information & special benefits.

NEWS ALERTS

Add your e-mail address here to receive the monthly TMS Software alerts.

 

LINKS

EXAMPLE 20

TAdvStringGrid

example 20 : using  HTML formatting capabilities

TAdvStringGrid

The 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.

The project and source files have been written with Delphi 6,7. To use these files in other versions of Delphi, ignore any remarks when opening the form files and save the files. After this, compilation can be done. The error messages are due to properties included in the Delphi 6 form file, but not available in lower versions of Delphi.  

Copyright © 1995 - 2008 TMS Software