Consider the following very simple unit:
Unit1.pas
unit Unit1;
interface
uses
Windows, Classes, Controls, Forms, ComCtrls;
type
TForm1 = class(TForm)
TreeView1: TTreeView;
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
SLongString = 'blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah';
procedure TForm1.FormCreate(Sender: TObject);
var
Node: TTreeNode;
begin
TreeView1.Width := 200;
Node := TreeView1.Items.Add(nil, SLongString);
Node.Text := 'blah';
end;
end.
Unit1.dfm
object Form1: TForm1
ClientHeight = 137
ClientWidth = 216
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object TreeView1: TTreeView
Left = 8
Top = 8
Width = 198
Height = 121
end
end
Add this to a VCL Forms app and run. The result looks like this:
I would like for the horizontal scroll bar not to be showing. How can I achieve this?
Now I realise that I could remove the line of code that assigns the very long string. But this is a cut-down program for the purpose of my question. In the real app the text of the nodes is changing and I want the scroll bars to show if they are needed, and not show if they are not needed.
I know about the TVS_NOHSCROLL
style but I can't use that. Sometimes the tree view contains text that is wider than the available space. And sometimes not.
I also want to use TTreeView
and do not want to use virtual tree view. Not that I have anything against virtual tree view, just that my app is currently using TTreeView
.
Very simple, use TreeView1.Items.BeginUpdate/EndUpdate
methods and the scrollbar will be calculated accordingly.
like this:
...
TreeView1.Items.BeginUpdate;
// change your nodes here
TreeView1.Items.EndUpdate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With