Search code examples
delphivcldelphi-10-seattlevirtualtreeviewtvirtualstringtree

TVirtualStringTree ScaleBy Stretch


I'm Trying to get a VST to resize automatically when its Height and Width is changed. I don't have this problem with other placed VCL components, some of them have a Property "Stretch" like TImage, which lets them adjust automatically. The VST remains stubborn and keeps nodeHeights and Column widths.

  • I have seen Header->hoAutoResize, hoColumnResize. In this matter, AutoSizeIndex <> -1 is not so useful, since I need every column to scale down. I think that's why these don't do anything. Changing the AutoSizeIndex to my last Column (3, because i have 4 Columns) and having hoAutoResize = True; still doesn't affect my column widths. hoColumnResize is the setting that lets the User resize columns, so no luck with that either
  • I have seen TreeOptions->AutoOptions->toAutoChangeScale and toAutoSpanColumns. I found out that toAutoSpanColumns is counter-productive in my case, so that's off. My Font-Size is adjusting.
  • I have found Tree.Scaleby, but I can't make it work in my favor and it's undocumented in the official .pdf docs I have.
  • All 4 columns have minWidth of 10, so no issue there
  • All 4 have coEnabled, coVisible, coResizable := True and coFixed, coSmartResize := False fwiw

I guess I'm just hitting the wrong combinations of settings or something. Any hints would be great, thanks.


Solution

  • From your post I understand that you want to automatically adjust widths of all columns proportionally when the TVirtualStringTree width changes. If you want that to also happen with the row heights, you can just apply the following correspondingly.

    There is no setting for the a propertional column width, but it is simple to achieve in the OnResize event of the TVirtualStringTree:

    procedure TForm1.VSTResize(Sender: TObject);
    begin
      VST.Header.Columns[0].Width := MulDiv(VST.Width, 50, 100);
      VST.Header.Columns[1].Width := MulDiv(VST.Width, 30, 100);
      VST.Header.Columns[2].Width := MulDiv(VST.Width, 20, 100);
    end;
    

    In the above, the columns are kept as 50%, 30% and 20% of the components width.