[SOLVED] VST coloring every other line lazarus / 31-LCL ---------------------------------------------------------------------- Pe3s · 2022-07-23 12:48 Hello, I wanted to do a coloring every second line in VirtualStringTree, how can I improve the code? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.VSTBeforeCellPaint(Sender: TBaseVirtualTree;  TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;  CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);begin     if Node.Index mod 2 = 0  then  begin    TargetCanvas.Brush.Color:= clMoneyGreen;    TargetCanvas.FillRect(CellRect);  end;end; ---------------------------------------------------------------------- jamie · 2022-07-23 13:16 This is a tricky situation because the Node index does not always reflect the actual line number you would need to work backwards to find the root node and then scan forward from the first root node to find out which location that tree lives in.  If you are only interested in the child nodes then you can scan backwards to its parent where you can then count forward to all the child nodes etc...  I think you understand what I mean.. I don't see any way for this at the moment.. looking at absolute index could be a solution but I am not sure about that one either. ---------------------------------------------------------------------- wp · 2022-07-23 13:46 Probably it is better to use AbsoluteIndex: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.VSTBeforeCellPaint(Sender: TBaseVirtualTree;  TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;  CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);begin  if Sender.AbsoluteIndex(Node) mod 2 = 0  then  begin    TargetCanvas.Brush.Color:= clMoneyGreen;    TargetCanvas.FillRect(CellRect);  end;end;But be aware that the AbsoluteIndex refers to the all-expanded state and does not change when nodes are expanded/collapsed. So, when you collapse nodes your alternating color sequence will not be in sync any more. ---------------------------------------------------------------------- Pe3s · 2022-07-23 14:07 I'm using VST as a table so the code works, Thank you