I have TVirtualStringTree and I want to change its nodes background color based on the nodes levels as this picture :
I have tried like this but its giving my desired result for the rows only:
procedure TForm1.VSTBeforeCellPaint(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
var
R: TRect;
begin
if CellPaintMode = cpmPaint then
begin
R := Sender.GetDisplayRect(Node, Column, True, False, True);
R.Offset(0, -R.Top);
case Sender.GetNodeLevel(Node) of
0: TargetCanvas.Brush.Color := $0000F9FF;
1: TargetCanvas.Brush.Color := $0000BFFF;
2: TargetCanvas.Brush.Color := $000086FF;
end;
TargetCanvas.FillRect(CellRect);
end;
end;

Not sure if its totally correct but its giving good result :
The Result :