1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
program listviewtest;
{$mode objfpc}{$H+}
uses
Classes, sysutils,
fpg_base, fpg_main, fpg_listview, fpg_form, fpg_button, fpg_edit, fpg_checkbox;
type
TMainForm = class(TfpgForm)
private
FEdit: TfpgEdit;
FAddButton: TfpgButton;
FListView: TfpgListView;
FTmpListView: TfpgListView;
FQuitButton: TfpgButton;
FCheck: TfpgCheckBox;
procedure CloseBttn(Sender: TObject);
procedure AddBttn(Sender: TObject);
procedure ShowHeadersChange(Sender: TObject);
procedure PaintItem(ListView: TfpgListView; ACanvas: TfpgCanvas; Item: TfpgLVItem;
ItemIndex: Integer; Area:TfpgRect; var PaintPart: TfpgLVItemPaintPart);
procedure ItemSelectionChanged(ListView: TfpgListView; Item: TfpgLVItem;
ItemIndex: Integer; Selected: Boolean);
public
constructor Create(AOwner: TComponent); override;
end;
{ TMainForm }
procedure TMainForm.CloseBttn(Sender: TObject);
begin
Close;
end;
procedure TMainForm.AddBttn(Sender: TObject);
var
Item: TfpgLVItem;
begin
FListView.BeginUpdate;
FTmpListView.BeginUpdate;
//FListView.Items.Capacity := FListView.Items.Capacity + 2000000;
//for I := 0 to 1999999 do begin
Item := FListView.ItemAdd;
Item.Caption := FEdit.Text + IntToStr(FListView.Items.Count);
Item.SubItems.Add('c0');
Item.SubItems.Add('c1');
Item.SubItems.Add('c2');
Item.SubItems.Add('c3');
Item.SubItems.Add('c4');
//end;
FListView.EndUpdate;
FTmpListView.EndUpdate;
end;
procedure TMainForm.ShowHeadersChange(Sender: TObject);
begin
FListView.ShowHeaders := TfpgCheckBox(Sender).Checked;
end;
procedure TMainForm.PaintItem(ListView: TfpgListView; ACanvas: TfpgCanvas;
Item: TfpgLVItem; ItemIndex: Integer; Area: TfpgRect; var PaintPart: TfpgLVItemPaintPart);
begin
if ItemIndex mod 2 = 0 then ACanvas.TextColor := clRed;
if ItemIndex mod 3 = 0 then ACanvas.TextColor := clBlue;
if ItemIndex mod 4 = 0 then ACanvas.TextColor := clGray;
if ItemIndex mod 5 = 0 then ACanvas.TextColor := clPink;
end;
procedure TMainForm.ItemSelectionChanged(ListView: TfpgListView;
Item: TfpgLVItem; ItemIndex: Integer; Selected: Boolean);
begin
WriteLn('Item changed: ', ItemIndex, ' ', Item.Caption, ' ',Selected);
end;
constructor TMainForm.Create(AOwner: TComponent);
var
LVColumn: TfpgLVColumn;
begin
inherited Create(AOwner);
WindowTitle := 'ListView Test';
SetPosition(200, 200, 610, 455);
FListView := TfpgListView.Create(Self);
with FListView do begin
Parent := Self;
Top := 10;
Left := 10;
Width := 320;
Height := 400;
OnPaintItem := @PaintItem;
OnSelectionChanged := @ItemSelectionChanged;
MultiSelect := True;
end;
FTmpListView := TfpgListView.Create(Self);
with FTmpListView do begin
Parent := Self;
Top := 10;
Left := 335;
Width := 270;
Height := 400;
//OnPaintItem := @PaintItem;
Items := FListView.Items;
end;
LVColumn := TfpgLVColumn.Create(FListView.Columns);
LVColumn.Caption := 'Column 1';
LVColumn.Width := 150;
LVColumn.Height := 50;
LVColumn.Resizable := True;
LVColumn.Alignment := taRightJustify;
FListView.Columns.Add(LVColumn);
FTmpListView.Columns.Add(LVColumn);
LVColumn := TfpgLVColumn.Create(FListView.Columns);
LVColumn.Caption := 'Column 2';
LVColumn.Width := 100;
LVColumn.Height := 50;
LVColumn.Alignment := taCenter;
//LVColumn.Visible := False;
FListView.Columns.Add(LVColumn);
//FTmpListView.Columns.Add(LVColumn);
LVColumn := TfpgLVColumn.Create(FListView.Columns);
LVColumn.Caption := 'Column 3';
LVColumn.Width := 200;
LVColumn.Height := 50;
//LVColumn.Visible := False;
LVColumn.Resizable := True;
LVColumn.Alignment := taRightJustify;
FListView.Columns.Add(LVColumn);
FTmpListView.Columns.Add(LVColumn);
LVColumn.ColumnIndex := 2;
FEdit := TfpgEdit.Create(Self);
with FEdit do begin
Parent := Self;
Top := 420;
Left := 10;
Width := 100;
end;
FAddButton := TfpgButton.Create(Self);
with FAddButton do begin
Parent := Self;
Top := 420;
Left := 120;
Width := 80;
Text := 'Add';
OnClick := @AddBttn;
end;
FQuitButton := TfpgButton.Create(Self);
with FQuitButton do begin
Parent := Self;
ImageName := 'stdimg.Quit';
ShowImage := True;
Top := 420;
Left := 210;
Width := 80;
Text := 'Quit';
OnClick := @CloseBttn;
end;
FCheck := TfpgCheckBox.Create(Self);
with FCheck do begin
Parent := Self;
Top := 420;
Left := 290;
Width := 110;
Checked := True;
Text := 'ShowHeaders';
OnChange := @ShowHeadersChange;
end;
end;
begin
fpgApplication.Initialize;
with TMainForm.Create(nil) do
begin
Show;
fpgApplication.Run;
Free;
end;
end.
|