What is the best way to label over the top Delphi TVirtualTreeView node icon

I am converting a tree view from a standard TTreeView to use TVirtualStringTree. My last task is to implement a function in which I need to draw a status indicator "pass / fail" on the icon of the famous node icon. Using TTreeView, I used:

  var
   R : TRect;
  begin
    R := Node.DisplayRect( True );
    StatusIconList.Draw( TreeView1.Canvas,
                         R.Left - StatusIconList.Width - 14,
                         R.Top,
                         3 {MyOverlayImageIndex} );

The result is a red cross above the main icon, as shown below:

enter image description here

With TVirtualStringTree, I was hoping to find either a better way or get better known positions for the required position of the overlay icon. I do:

   procedure DrawFailed;
    var
     R : TRect;
    begin
      R := CellRect;
      StatusIconList.Draw( TargetCanvas,
                           R.Left - StatusIconList.Width + 49 + Sender.GetNodeLevel( Node ) * 16,
                           R.Top,
                           siiFailed );
    end;

Is this the best solution? Is there a better way to get the top / left corner of the main icon without a horrible node level call?

+5
1

Kind: TVTImageKind OnGetImageIndex. ikOverlay .

+8

All Articles