PRODUCTS » Quick Links

FEATURED PRODUCT

Set of VCL components to offer easy access from Windows applications to cloud services

License only 150 EUR See More

LOGIN

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

SEARCH

STAY IN TOUCH

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

 
PRODUCTS » VCL COMPONENTS » TADVSTRINGGRID » EXAMPLE 60

TAdvStringGrid

Example 60 : Using data dependent images with TAdvStringGrid

TAdvStringGrid

The method grid.AddDataImage(col,row,index,horizAlign,vertAlign) adds an imagelist image to a cell. The index of this imagelist image is dependent of the data in the cell where the image is added. By default, this means that when the cell has the value 0, the first image of the imagelist will be displayed, when the value is 1, the second image will be displayed etc... Not in all circumstances it is convenient that the cell data should be a number. Suppose that we want to display a Yes / No field with textual representation 'Y' and 'N' as two distinct images in the grid from an imagelist.  Normally, this would not be possible, but thanks to the OnGetDisplText, a solution is easily implemented. This OnGetDisplText will convert the values 'Y' and 'N' to the imagelist index values that are needed to display the proper images.  The code snippet that takes care of this is:

procedure TForm1.AdvStringGrid1GetDisplText(Sender: TObject; ACol,
  ARow: Integer; var Value: String);
var
  oldvalue: string;
begin
  oldvalue := value;
  if (ACol = 1) and (ARow > 0) then
  begin
    if value = 'Y' then
      value := '1'
    else
      value := '0';

  end;
end;

With this one event handler, we can set images through:

advstringgrid1.Cells[1,1] := 'N';
advstringgrid1.Cells[1,2] := 'Y';

and just use the text that is most convenient for maintaining in the rest of the application.

Delphi project & source files for downloading included in the main demos distribution for Delphi.

Copyright © 1995 - 2013 TMS Software v3.5