TTMSFMXTreeview ColumnSize issue

There is something very strange going on with "single column" treeviews and the column width.

Hard to describe, but (relatively) easy to reproduce.

1. Create a new Multi-Device App
2. Drop a TMSFMXTreeview and a TButton
3. Properties Treeview
   ColumnAppearance.Layout = []
   HoriztontalScrollbarVisible = True
   VerticalScrollbarVisible = True
   Width = 300 (unchanged)
4. Implement events FormCreate and Button1Click (see below)
5. Run the app
6. Click the Button 

procedure TForm1.FormCreate(Sender: TObject);
var
  i   : Integer;
  col : TTMSFMXTreeViewColumn;
  pn  : TTMSFMXTreeViewNode;
begin
  TMSFMXTreeView1.ClearNodes;
  TMSFMXTreeView1.Columns.Clear;

  col := TMSFMXTreeView1.Columns.Add;

  for i := 1 to 25 do
  begin
    pn         := TMSFMXTreeView1.AddNode;
    pn.Text[0] := IntToStr(i) + ' It has to be a large example text to force the horizontal scrollbar';
  end;

  TMSFMXTreeView1.AutoSizeColumn(0);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if TMSFMXTreeView1.ColumnsAppearance.Layouts = [] then
    TMSFMXTreeView1.ColumnsAppearance.Layouts := [TTMSFMXTreeViewColumnsLayout.tclTop]
  else
    TMSFMXTreeView1.ColumnsAppearance.Layouts := [];
end;


Hi, 


Can you please describe exactly what the issue is, when we test this here we do not see a horizontal scrollbar appear?

Horizontal scrollbar goes away, and the columnwidth is reduced to about half of the Treeview width.

Not seeing the horizontal scrollbar would be another bug, because HorizontaScrollbarVisible = True
I will send an email with screenshots

Thank you

Mail has been sent...

Hi Pieter,


Thx for the enormous support.

Overriding the UpdateAutoSizing method does the trick.
It seems that the application displays the Treeviews correctly now.

I'm extremely glad that this issue seems resolved.
So thanks again, and enjoy the weekend.

Hi, 


Thank you for your valuable feedback!
If anything comes up, please let us know.

John,

Can you post your trick?

Hi Zoltan,


I have created a descendant Treeview component and there were display issues when haveing only 1 column and a (visible) horizontal scrollbar.

Below the code from Pieter that fixed my problem.

type
  TMyTreeView = class(TTMSFMXTreeView)
  private
    FBlockUpdate : Boolean;
  protected
    procedure UpdateAutoSizing; override;
  end;

procedure TMyTreeView.UpdateAutoSizing;
var
  w: Double;
begin
  inherited;

  if (ColumnCount <> 1) or FBlockUpdate then
    Exit;

  FBlockUpdate := True;
  try
    ColumnsAppearance.Stretch := False;
    AutoSizeColumn(0);
    w := Width;
    if VerticalScrollBar <> nil then
      w := w - VerticalScrollBar.Width;

    ColumnsAppearance.Stretch    := ColumnWidths[0] <= w;
    ColumnsAppearance.StretchAll := ColumnsAppearance.Stretch;
  finally
    FBlockUpdate := False;
  end;
end;

John,


Thank you for sharing your source codes.