3

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.

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Artem E
  • 369
  • 1
  • 4
  • 19

1 Answers1

5

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;
ain
  • 22,394
  • 3
  • 54
  • 74
  • The `toAutoSpanColumns` seems to be intended for this purpose (didn't know it), but in my quick test (Delphi 2009, VT 5.1.0) the next column still covers the previous one (without considering its own emptiness). – TLama Sep 03 '13 at 21:27
  • 1
    It depends what the OP really wants... my ipression is that he needs the caption of child column to be fully readable, not cut off by the end of the column. For that `toAutoSpanColumns` should do... – ain Sep 04 '13 at 05:12
  • 1
    Yes, I got it the same, but it didn't work for me. I've made what you described, but the second column still covered all the (sub)nodes. I forgot to add that all I modified was I made the header visible with 2 columns. The rest of the settings (except `toAutoSpanColumns`) I kept in default. – TLama Sep 04 '13 at 06:48
  • Hmm, I have used the AutoSpan option in the past (with VT 5 version) and it works... I think I have never needed it to work for only some nodes, so I have not used it with `OnGetCellIsEmpty` event - could you try without one too? Unfortunately I don't have my code neither VT installed here so can't check myself... – ain Sep 04 '13 at 06:49
  • Haven't checked that in source, but a quick test confirms that. The `OnGetCellIsEmpty` doesn't seem to affect column spanning as expected. In my yesterday's test I've kept the cells in the second column to have text (from the `DefaultText` property value) and used the `OnGetCellIsEmpty` to convince the tree that the cell is empty (when it isn't), but it seems this to be ignored. Today I cleared the `DefaultText` property value and it works as expected, so it seems that higher priority has the node text itself. Hard to say, something might change in this. [+1] – TLama Sep 04 '13 at 07:08