ADVStringGrid AddPicture into cell beforetext

Hello
I fill and trying to add diference pictograms to cells before text.
It should be

But when i use AddPicture it looks

My pictures are stored in PictureContainer

    while not Query.Eof do
    begin
      Grid.Ints[0, Query.recno + 1] := Query.FieldByName('ArtNr').asinteger;
      
      if Query.FieldByName('checked').isnull then
        Grid.AddPicture(0, Query.RecNo + 1, PictureContainer1.FindBitmap('HOURGLASS'), false, StretchWithAspectRatio, 8, haLeft, vaCenter)
//        Grid.AddImageIdx(0, Query.RecNo + 1, 2, haLeft, vaCenter)
      else
      begin
        if Query.FieldByName('checked').AsBoolean then
          Grid.AddPicture(0, Query.RecNo + 1, PictureContainer1.FindBitmap('APPLY'), false, StretchWithAspectRatio, 8, haLeft, vaCenter)
//          Grid.AddImageIdx(0, Query.RecNo + 1, 0, haLeft, vaCenter)
        else if Query.FieldByName('checked').asboolean = false then
          Grid.AddPicture(0, Query.RecNo + 1, PictureContainer1.FindBitmap('BUTTON_CANCEL'), false, StretchWithAspectRatio, 8, haLeft, vaCenter);
//          Grid.AddImageIdx(0, Query.RecNo + 1, 1, haLeft, vaCenter);
      end;
      Query.Next;
    end;

but the last image is always taken and overwritten in all cells.
I tryed it with Grid.AddImage but there I cant resize the picture.
What I doing wrong with AddPicture?
With best regards V. Klamm

AddPicture() will add one picture.
If you need multiple images you can either use an imagelist and use AddMultiImage() or you can reference multiple images in a HTML formatted text you add to a grid cell.

Seems like

is always true.

Here addpicture w/ picturecontainer works fine.

Query.FieldByName('checked').isnull

no, is not, because if it false I check for value true or false in DB looks like
grafik
NULL / True / False

first screen is when I use addImage

In both cases(HTML or AddMultiimage()) I can´t use stretch for my pictures that stored in imagelist. Pictures stay allways small.
I use now CreateFilePicture() and store my images in app directory.

Maybe is it possible to extend AddPicture() to add images in cells from picturecontainer in the future versions of components?

For images via HTML, you can use the width and/or the height attribute to control the size of the rendered image

I tryed that

Cells[6, 2] := 'Including <IMG src="idx:0" style="height: 100%;">';

but it doesnt work for me

Try to use an absolute width

red and yello symbols are with CreateFilePicture() painted.

sggesf.cells[0,qgesf.RecNo +1]:='<IMG src="idx:0" style="height: 100%; width: absolute;">'

I checked html sample its work fine https://jsfiddle.net/f7bkmayd/

Absolute means something like:

width=“64px” height=“64px”

No, it doen´t work :frowning:

But calling AddPicture using a PictureContainer does work.
With the code you sent, the only ways to have this column full of hourglasses are:

1-Your dataset "check" field is always null, which you've already checked.
2-Your picture container has more hourglasses than you thought it did :grinning_face_with_smiling_eyes:

I've tested the using picturecontainer in office19 toolbar demo, where there's a advgrid with addpicture, and it work in many scenarios ... with/without fixed columns, with no fixed row, 1 fixed row, 2 fixed rows (your case)

For sure and again :grinning_face_with_smiling_eyes: .... Look at first screenshot where I use AddImage() there is my "checked" field never ever only NULL or FALSE or TRUE my code logic works fine :upside_down_face:

Yeah, becaus last entry im my loop was NULL thats why I create a topic to ask why and
@brunofierens said :

If I change my last entry to true or false it will show me only aplly or cancel signs

show it :smiley:

I meant maybe your picture container had no Apply or Cancel signs.
But NOOO! See below!

Wow! I tested it individually! When I put it in into the loop, everything changed!

There IS a third way you could get that column full of hourglasses:
3 - PictureContainer.FindBitmap always return a pointer to a internal bitmap object, so when you call it inside a loop, you're just replacing previous results. :man_facepalming:
So, AddPicture, that points to an external picture object won't fit. Must use CreatePicture instead.

Try:

  while not Query.Eof do
    begin
      Grid.Ints[0, Query.recno + 1] := Query.FieldByName('ArtNr').asinteger;
      
      if Query.FieldByName('checked').isnull then
        Grid.CreatePicture(0, Query.RecNo + 1, false, StretchWithAspectRatio, 8, haLeft, vaCenter).Assign(PictureContainer1.FindBitmap('HOURGLASS'))
      else
      begin
        if Query.FieldByName('checked').AsBoolean then
          Grid.CreatePicture(0, Query.RecNo + 1, false, StretchWithAspectRatio, 8, haLeft, vaCenter).Assign(PictureContainer1.FindBitmap('APPLY'))
        else if Query.FieldByName('checked').asboolean = false then
          Grid.CreatePicture(0, Query.RecNo + 1, false, StretchWithAspectRatio, 8, haLeft, vaCenter).Assign(PictureContainer1.FindBitmap('BUTTON_CANCEL'));
      end;
      Query.Next;
    end;

That wasn´t clear for me.

And I wrote before that works with functions

CreatePicture

or

CreateFilePicture

Sorry, I didn't see it.
Somewhere above there's a CreateFilePicture reference. Is it?

The source code I sent is using Grid.CreatePicture with the PictureContainer.

The Result of FindBitmap function is a TPictureContainer local object variable that is constantly freed/created. Thats why it doesn't work well with AddPicture, that relays on existing bitmap objects.

1 Like