PRODUCTS

FEATURED PRODUCT

Grid, menus, calendars, advanced edits, navigational controls and much more... to create feature-rich IntraWeb applications faster

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 43

TAdvStringGrid

example 43 : advanced border control

In earlier versions of TAdvStringGrid, it was not possible to specify different border colors and widths for a single cell. It was only possible to specify which border to draw (left, top, bottom, right)

In addition to the OnGetCellBorder event with which you can specify which borders to draw, an extra event is now available, OnGetCellBorderProp through which the pen can be set for the left, top, bottom and right border of the cell.

How the 2 events work together is shown in the following example:

procedure TForm1.AdvStringGrid1GetCellBorder(Sender: TObject; ARow,
  ACol: Integer; APen: TPen; var Borders: TCellBorders);
begin
  if not Odd(ACol) and (ARow > 0) and (ACol > 0) then
  begin
    Borders := [cbLeft];
    APen.Width := 1;
    APen.Color := clBlack;
  end;

  if not Odd(ARow) and (ARow > 0) and (ACol > 0) then
  begin
    Borders := Borders + [cbBottom];
    APen.Width := 1;
    APen.Color := clBlack;
  end;
end;

The above event handler makes sure that a left and bottom border of the cell are only drawn for all even rows. The specify that the left border should be drawn in a blue color and the bottom border in a red color, the OnGetCellBorderProp method is used :

procedure TForm1.AdvStringGrid1GetCellBorderProp(Sender: TObject; ARow,
  ACol: Integer; LeftPen, TopPen, RightPen, BottomPen: TPen);
begin
  LeftPen.Color := clBlue;

  BottomPen.Color := clRed;
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