Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I show virtual tree-view grid lines for nodes that don't exist yet?

I use SoftGem's VirtualStringTree in Delphi 7.

Is there a way to enable full grid lines (just as in a TListView)? I can only find toShowHorzGridLines, which only shows lines for current nodes, not anything in the empty space below, and toShowVertGridLines, which shows only vertical lines.

How do I show them in the empty space before items are added?

like image 531
Ben Avatar asked Jun 25 '12 11:06

Ben


1 Answers

I don't think there is an easy way to implement this without modifying PaintTree method since none of the node events cannot be fired because nodes whose lines should be drawn simply doesn't exist yet.

Here is an dirty way how to additionally draw the horizontal lines based on the lowest visible node. In fact it draws lines with distance of the DefaultNodeHeight value in the area filled by orange color in this screenshot:

enter image description here

Here is the code:

type
  TVirtualStringTree = class(VirtualTrees.TVirtualStringTree)
  public
    procedure PaintTree(TargetCanvas: TCanvas; Window: TRect; Target: TPoint;
      PaintOptions: TVTInternalPaintOptions; PixelFormat: TPixelFormat = pfDevice); override;
  end;

implementation

{ TVirtualStringTree }

procedure TVirtualStringTree.PaintTree(TargetCanvas: TCanvas; Window: TRect;
  Target: TPoint; PaintOptions: TVTInternalPaintOptions;
  PixelFormat: TPixelFormat);
var
  I: Integer;
  EmptyRect: TRect;
  PaintInfo: TVTPaintInfo;
begin
  inherited;
  if (poGridLines in PaintOptions) and (toShowHorzGridLines in TreeOptions.PaintOptions) and
    (GetLastVisible <> nil) then
  begin
    EmptyRect := GetDisplayRect(GetLastVisible,
      Header.Columns[Header.Columns.GetLastVisibleColumn].Index, False);
    EmptyRect := Rect(ClientRect.Left, EmptyRect.Bottom + DefaultNodeHeight,
      EmptyRect.Right, ClientRect.Bottom);
    ZeroMemory(@PaintInfo, SizeOf(PaintInfo));
    PaintInfo.Canvas := TargetCanvas;
    for I := 0 to ((EmptyRect.Bottom - EmptyRect.Top) div DefaultNodeHeight) do
    begin
      PaintInfo.Canvas.Font.Color := Colors.GridLineColor;
      DrawDottedHLine(PaintInfo, EmptyRect.Left, EmptyRect.Right,
        EmptyRect.Top + (I * DefaultNodeHeight));
    end;
  end;
end;

And here the result with constant and variable node height:

enter image description here

The glitch (the lines shifted from the left side) visible on the screenshot above is just a consequence of a dotted line rendering. If you set the LineStyle property on your virtual tree view to lsSolid you will see the correct result.

like image 150
TLama Avatar answered Oct 11 '22 22:10

TLama