5

I'm converting a tree view from the standard TTreeView to use TVirtualStringTree. My final challenge is to implement a feature where I need to draw a 'pass/fail' status indicator on top of the known node icon. With 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 the red cross over the basic icon as shown below:

enter image description here

With TVirtualStringTree I hoped to find either a better way, or to get better known positions for the required overlay icon position. I'm doing:

   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 of getting the top/left corner of the basic icon without the horrible node level call?

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Brian Frost
  • 13,334
  • 11
  • 80
  • 154

1 Answers1

9

You get Kind: TVTImageKind parameter in your OnGetImageIndex event handler. Check it for ikOverlay and simply return the appropriate image index.

Ondrej Kelle
  • 36,941
  • 2
  • 65
  • 128
  • That's a good point, thanks. I've added a couple of images to my image list (eg indexes 8 & 9), called MyImageList.Overlay( 8,0 ) and MyImageList.Overlay( 9,1 ) and arranged OnGetImageIndex to return 0 or 1 when Kind is ikOverlay. No overlays appear though, only the basic icons. Is there another switch I need to set please? THanks. – Brian Frost Jun 03 '11 at 15:21
  • 1
    That's exactly what needs to be done, I just tried it and it works, I'm not aware of anything else, sorry. – Ondrej Kelle Jun 03 '11 at 18:16