TAdvTreeView GetNodeIcon from TPictureContainer


i would like to use an image from a TPictureContainer in the GetNodeIcon Event of the TAdvTreeView Component. I havent been working on this code a while but i remember that worked.

The types do not match and i cannot find a solution at the moment, but i think there is a simple one but i cannot figure it out.

Hopefully someone can help :slight_smile:


procedure TfrmWebsiteBooster.tvSearchEngineListGetNodeIcon(Sender: TObject;
  ANode: TAdvTreeViewVirtualNode; AColumn: Integer; ALarge: Boolean;
  var AIcon: TAdvBitmap);
 if AColumn = 0 then
  if ANode.Node.DataObject <> nil then
   if ANode.Node.DataObject.ClassName = 'TSearchEngineProviderListItem' then
    // TSearchEngineProviderListItem
    if TSearchEngineProviderListItem(ANode.Node.DataObject).ItemIconIndex <> -1 then
     if TSearchEngineProviderListItem(ANode.Node.DataObject).ItemIconIndex <= SearchEngineListPictureContainer.Items.Count - 1 then
      if Assigned(tvSearchEngineList.PictureContainer) then
       AIcon := SearchEngineListPictureContainer.Items.Items[TSearchEngineProviderListItem(ANode.Node.DataObject).ItemIconIndex].Picture;

Can you try

AIcon := TAdvBitmap(PictureContainer.Items[x].Picture);

I tried that but there is no icon displayed ... i checked that the PictureContainer is set and the images are in the Container but it seems that the Image/Icon is not used and will not be displayed

When you check AIcon.Width / AIcon.Height, do you get the expected dimensions?

No ... there are both always 0 ... by the way ... not sure if this information is needed or helpfull ... i use checkboxes for every node in the tree

That would indicate retrieval of the picture from the PictureContainer isn't working correct.
Can you access the picture (and its width/height) correct outside this TAdvTreeView event handler?

Just tested that an read out every item width and height from the TPictureContainer and everything is ok

This is puzzling that from the event you cannot read out width & height properly but from another place in your code you can?
Can this be isolated and a sample source project sent with which we can reproduce this here?

Of course ... i will create a small demo from the code asap :slight_smile:

Hi, thank you for the sample. The test is showing the correct image sizes, however for dynamic image sizes, TAdvTreeView is expecting a TAdvBitmap (TPicture), whereas TPictureContainer is returning a TGraphic, not a TPicture. Casting a TGraphic to a TPicture or TAdvBitmap does not work. Instead, you'll have to create an internal list to handle the data separately. The list is filled dynamically based on the name of the image. If the image is included in the list, it will not be added again. please see the modified sample. TestProject.zip (280.7 KB)

Also, please note that you can attach a sample to your post.


Thanks a lot ...

sorry ... i did not see that attaching samples will work this way ... i will use that feature in future.

Have a great day and stay healthy, You all do a great job.


This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.