Components for Delphi and C++ Builder.

Go to Russian forum
Go to EhLib.com
It is currently 28 Mar 2024, 09:17

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: 30 Mar 2020, 21:28 
Offline

Joined: 30 Mar 2020, 17:08
Posts: 1
Hello!

Exist the possibility of put on two image in one cell/column from grideh?
According the image to the attachment.

Thank's...


Attachments:
image (3).png
image (3).png [ 6.28 KiB | Viewed 1509 times ]
Top
 Profile  
 
PostPosted: 03 Apr 2020, 18:37 
Offline

Joined: 08 May 2014, 18:06
Posts: 660
Hello

There are no special properties in the grid to configure the display of multiple images in cells.
But you can easily implement this in the Column.OnAdvDrawDataCell event.

Here is sample code for the event and a demo project.

Code:
//  ColumnEh.OnAdvDrawDataCell event handler
procedure TForm1.DBGridEh1Columns1AdvDrawDataCell(Sender: TCustomDBGridEh; Cell,
  AreaCell: TGridCoord; Column: TColumnEh; const ARect: TRect;
  var Params: TColCellParamsEh; var Processed: Boolean);
var
  ImageIndices: TIntegerDynArray;
begin
  Sender.DefaultDrawColumnDataCell(Cell, AreaCell, Column, ARect, Params);
  ImageIndices := GetImages();
  DrawImages(ImageIndices, ARect);
  Processed := True;
end;

//Get array of image Indices from ImageList1
function TForm1.GetImages(): TIntegerDynArray;
var
  f: TField;
  len: Integer;
begin
  SetLength(Result, 0);
  len := 0;
  f := MemTableEh1.FieldByName('Area');
  if (f.AsInteger > 10000) then
  begin
    SetLength(Result, len+1);
    Result[len] := len;
    len:= len+ 1;
  end;
  if (f.AsInteger > 100000) then
  begin
    SetLength(Result, len+1);
    Result[len] := len;
    len:= len+ 1;
  end;
  if (f.AsInteger > 1000000) then
  begin
    SetLength(Result, len+1);
    Result[len] := len;
    len:= len+ 1;
  end;
  if (f.AsInteger > 10000000) then
  begin
    SetLength(Result, len+1);
    Result[len] := len;
    len:= len+ 1;
  end;
end;

//Draw array of images from ImageIndices array
//ARect - Cell bounds
procedure TForm1.DrawImages(ImageIndices: TIntegerDynArray; const ARect: TRect);
var
  i: Integer;
  pos: TPoint;
  w: Integer;
begin
  pos := ARect.Location;
  w := ImageList1.Width * Length(ImageIndices);
  pos.X := pos.X + (ARect.Width - w) div 2;

  for i := 0 to Length(ImageIndices) - 1 do
  begin
    ImageList1.Draw(DBGridEh1.Canvas, pos.X, pos.y, ImageIndices[i]);
    pos.X := pos.X + ImageList1.Width;
  end;
end;


Attachments:
DBGridEh.MultiImagesInCell.zip [7.1 KiB]
Downloaded 113 times
sshot-2.png
sshot-2.png [ 10.98 KiB | Viewed 1484 times ]
sshot-3.png
sshot-3.png [ 30.61 KiB | Viewed 1484 times ]

_________________
Best regards
EhLib Support Team
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 63 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group