VirtualTreeView. How to modify child column width?

1.4k Views Asked by At

My friend is working in Delphi with VirtualTreeView and has next problem: He has two columns with data and childs for every row in first column. Is that possible not changing first column width to set maximum child column width?

task

Legend:

  • Circles are nodes
  • rectangles are text (black rectangles of root nodes are two column)

How it looks now - look child black reactangle. How it have to be - look red rectangle.

1

There are 1 best solutions below

5
On

This is called column spanning and yes, it can be done quite easily - just set the TreeOptions -> AutoOptions -> toAutoSpanColumns option to True. The way it works is that if the adjacent column is empty then the caption of the current one is extended into it. As you only want it to work for child columns you have to implement OnGetCellIsEmpty event and return IsEmpty := True only for child nodes, ie something like

procedure TForm1.VT_GetCellIsEmpty(Sender: TBaseVirtualTree;
          Node: PVirtualNode; Column: TColumnIndex; var IsEmpty: Boolean);
begin
  IsEmpty := (Sender.GetNodeLevel(Node) > 0);
end;