Create a master part view with a title in a group of items in a virtual Treeview (TVirtualStringTree)

I am trying to get a result that looks like this from TVirtualStringTree:

desired virtualtreeview appearance

I believe this is possible either directly with TVirtualStringTree (the main Virtual TVirtualStringTree control by Mike Lishke), either by subclassing and modifying the inherited control, or by switching to TVirtualDrawTree .

Here is what I can get, and shows the problem I am facing:

actual vritualtreeview appearance

The problem is that I cannot get the text for column 0 to cover the entire horizontal area of ​​the virtual tree control. There is a virtual tree view demo in an extended demo showing multi-line text that seems to do what I need, but I can't figure out how to apply it in combination with the detailed columns that I need below the title bar (shown as Node , Node, Node in the picture).

Here is what I tried:

  • Change the ContentRect.Right event in the BeforeCellPaint event:
  • set toGridExtensions on to TreeOptions.MiscOptions .

Here is a sample code showing how I tried to change the contentRect:

 procedure TForm1.VirtualStringTree1BeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect); var level:Integer; begin level := VirtualStringTree1.GetNodeLevel(Node); if (level=0) then Inc( ContentRect.Right, 300); end; 

Update:

Using the answer below, I get the following:

enter image description here

+6
source share
1 answer

I think you want to use the toAutoSpanColumns option (in TreeOptions.AutoOptions ), possibly with the OnGetCellIsEmpty event (not necessary if you return text only for the first column).

To get multi-line nodes, start them with the ivsMultiline state (in the OnInitNode event) or set vtree.MultiLine[Node] := boolean;

+5
source

Source: https://habr.com/ru/post/896135/


All Articles