### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: To learn VirtualTreeView  (Read 5232 times)

#### asdf

• Sr. Member
• Posts: 310
##### To learn VirtualTreeView
« on: February 23, 2011, 12:52:47 pm »
Quote
procedure TForm1.FormCreate(Sender: TObject);

var
n: integer;
m: string;

begin

for n:=0 to 8 do begin
VirtualStringTree1.Header.Columns.Add;
if n = 0  then m:= 'Zone';
if n = 1  then m:= 'Year';
if n = 2  then m:= 'Month';
if n = 3  then m:= 'Date';
if n = 4  then m:= 'Flour';
if n = 5  then m:= 'Sugar';
if n = 6  then m:= 'Butter';
if n = 7  then m:= 'Total';
if n = 8  then m:= 'Salesperson';
VirtualStringTree1.Header.Columns[n].Text:=m;
VirtualStringTree1.Header.Columns[n].Width:=100;
end;

for n:=0 to 3 do
VirtualStringTree1.Header.Columns[n].Options:=VirtualStringTree1.Header.Columns[n].Options
-[coAllowClick];

VirtualStringTree1.Header.Options:=VirtualStringTree1.Header.Options
+[hoVisible];

VirtualStringTree1.Header.Style:=hsXPStyle;

VirtualStringTree1.TreeOptions.PaintOptions:=VirtualStringTree1.TreeOptions.PaintOptions
+[toshowtreelines]
+[toshowroot];

VirtualStringTree1.TreeOptions.MiscOptions:=VirtualStringTree1.TreeOptions.MiscOptions
+[toEditable];

VirtualStringTree1.TreeOptions.SelectionOptions:=VirtualStringTree1.TreeOptions.SelectionOptions
+[toExtendedFocus]
+[toMultiSelect];

Form1.WindowState:=wsmaximized;

end;

procedure TForm1.LoadDataIntoTreeMenuItemClick(Sender: TObject);

var

XNode: PVirtualNode;

begin

XNode:=VirtualStringTree1.AddChild(nil);

end;

I'm learning to use VirtualTreeview,

What is XNode: PVirtualNode; ?

And from the attachment, how can I write codes to get VirtualTreeView 1, 2, 3 & 4 ?
« Last Edit: February 23, 2011, 07:21:09 pm by asdf »
Lazarus 1.2.4 / Win 32 / THAILAND

#### asdf

• Sr. Member
• Posts: 310
##### Re: To learn VirtualTreeView
« Reply #1 on: February 24, 2011, 05:15:58 pm »
Finally I just moved to use TreeListView instead.
It looks easier and I could finish learning/practicing the example within 1 hour.
Lazarus 1.2.4 / Win 32 / THAILAND

#### ik

• Jr. Member
• Posts: 88
• ik
##### Re: To learn VirtualTreeView
« Reply #2 on: February 24, 2011, 11:48:04 pm »
One note: instead of all the If statement can use a case statement, it's more efficient.
Another option is a constant of const (unless you are going to translate it) and do something like this:

Code: Pascal  [Select][+][-]
1. const
2.  arrNames : array[0..8] of string = ('Zone', 'Year', 'Month' ...
3.