mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 05:39:17 +02:00
Examples: listview: added OwnerData mode, added property ReadOnly, AutoWidthLastColumn, fixed exceptions. issue #18898
git-svn-id: trunk@35268 -
This commit is contained in:
parent
9fba3d205f
commit
cd7931e012
@ -1,75 +1,75 @@
|
|||||||
object Form1: TForm1
|
object Form1: TForm1
|
||||||
Left = 356
|
Left = 356
|
||||||
Height = 299
|
Height = 360
|
||||||
Top = 150
|
Top = 150
|
||||||
Width = 627
|
Width = 620
|
||||||
HorzScrollBar.Page = 626
|
HorzScrollBar.Page = 626
|
||||||
VertScrollBar.Page = 298
|
VertScrollBar.Page = 298
|
||||||
ActiveControl = CheckBox3
|
ActiveControl = CheckBox3
|
||||||
Caption = 'Listview test'
|
Caption = 'Listview test'
|
||||||
ClientHeight = 299
|
ClientHeight = 360
|
||||||
ClientWidth = 627
|
ClientWidth = 620
|
||||||
LCLVersion = '0.9.31'
|
LCLVersion = '0.9.31'
|
||||||
object PageControl1: TPageControl
|
object PageControl1: TPageControl
|
||||||
Left = 433
|
Left = 399
|
||||||
Height = 280
|
Height = 341
|
||||||
Top = 8
|
Top = 8
|
||||||
Width = 184
|
Width = 211
|
||||||
ActivePage = Page3
|
ActivePage = Page3
|
||||||
Anchors = [akTop, akRight]
|
Anchors = [akTop, akRight]
|
||||||
TabIndex = 0
|
TabIndex = 0
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
object Page3: TTabSheet
|
object Page3: TTabSheet
|
||||||
Caption = 'LV'
|
Caption = 'LV'
|
||||||
ClientHeight = 254
|
ClientHeight = 307
|
||||||
ClientWidth = 176
|
ClientWidth = 205
|
||||||
object Label11: TLabel
|
object Label11: TLabel
|
||||||
Left = 6
|
Left = 6
|
||||||
Height = 14
|
Height = 17
|
||||||
Top = 60
|
Top = 60
|
||||||
Width = 47
|
Width = 59
|
||||||
Caption = 'Scrollbars'
|
Caption = 'Scrollbars'
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
end
|
end
|
||||||
object Label12: TLabel
|
object Label12: TLabel
|
||||||
Left = 6
|
Left = 6
|
||||||
Height = 14
|
Height = 17
|
||||||
Top = 122
|
Top = 122
|
||||||
Width = 56
|
Width = 69
|
||||||
Caption = 'SortColumn'
|
Caption = 'SortColumn'
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
end
|
end
|
||||||
object Label13: TLabel
|
object Label13: TLabel
|
||||||
Left = 6
|
Left = 6
|
||||||
Height = 14
|
Height = 17
|
||||||
Top = 154
|
Top = 154
|
||||||
Width = 45
|
Width = 52
|
||||||
Caption = 'SortType'
|
Caption = 'SortType'
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
end
|
end
|
||||||
object Label14: TLabel
|
object Label14: TLabel
|
||||||
Left = 6
|
Left = 6
|
||||||
Height = 14
|
Height = 17
|
||||||
Top = 186
|
Top = 186
|
||||||
Width = 47
|
Width = 59
|
||||||
Caption = 'ViewStyle'
|
Caption = 'ViewStyle'
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
end
|
end
|
||||||
object CheckBox3: TCheckBox
|
object CheckBox3: TCheckBox
|
||||||
Left = 6
|
Left = 6
|
||||||
Height = 17
|
Height = 22
|
||||||
Top = 4
|
Top = 4
|
||||||
Width = 68
|
Width = 87
|
||||||
Caption = 'Multiselect'
|
Caption = 'Multiselect'
|
||||||
OnClick = CheckBox3Click
|
OnClick = CheckBox3Click
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
end
|
end
|
||||||
object ComboBox2: TComboBox
|
object ComboBox2: TComboBox
|
||||||
Left = 77
|
Left = 77
|
||||||
Height = 21
|
Height = 26
|
||||||
Top = 52
|
Top = 52
|
||||||
Width = 95
|
Width = 95
|
||||||
ItemHeight = 13
|
ItemHeight = 0
|
||||||
ItemIndex = 6
|
ItemIndex = 6
|
||||||
Items.Strings = (
|
Items.Strings = (
|
||||||
'ssNone'
|
'ssNone'
|
||||||
@ -87,7 +87,7 @@ object Form1: TForm1
|
|||||||
end
|
end
|
||||||
object Edit11: TEdit
|
object Edit11: TEdit
|
||||||
Left = 78
|
Left = 78
|
||||||
Height = 21
|
Height = 22
|
||||||
Top = 116
|
Top = 116
|
||||||
Width = 80
|
Width = 80
|
||||||
OnChange = Edit11Change
|
OnChange = Edit11Change
|
||||||
@ -96,10 +96,10 @@ object Form1: TForm1
|
|||||||
end
|
end
|
||||||
object ComboBox3: TComboBox
|
object ComboBox3: TComboBox
|
||||||
Left = 77
|
Left = 77
|
||||||
Height = 21
|
Height = 26
|
||||||
Top = 146
|
Top = 146
|
||||||
Width = 95
|
Width = 95
|
||||||
ItemHeight = 13
|
ItemHeight = 0
|
||||||
ItemIndex = 0
|
ItemIndex = 0
|
||||||
Items.Strings = (
|
Items.Strings = (
|
||||||
'stNone'
|
'stNone'
|
||||||
@ -114,10 +114,10 @@ object Form1: TForm1
|
|||||||
end
|
end
|
||||||
object ComboBox4: TComboBox
|
object ComboBox4: TComboBox
|
||||||
Left = 78
|
Left = 78
|
||||||
Height = 21
|
Height = 26
|
||||||
Top = 178
|
Top = 178
|
||||||
Width = 95
|
Width = 95
|
||||||
ItemHeight = 13
|
ItemHeight = 0
|
||||||
ItemIndex = 3
|
ItemIndex = 3
|
||||||
Items.Strings = (
|
Items.Strings = (
|
||||||
'vsIcon'
|
'vsIcon'
|
||||||
@ -132,18 +132,18 @@ object Form1: TForm1
|
|||||||
end
|
end
|
||||||
object CheckBox4: TCheckBox
|
object CheckBox4: TCheckBox
|
||||||
Left = 6
|
Left = 6
|
||||||
Height = 17
|
Height = 22
|
||||||
Top = 28
|
Top = 28
|
||||||
Width = 68
|
Width = 86
|
||||||
Caption = 'RowSelect'
|
Caption = 'RowSelect'
|
||||||
OnClick = CheckBox4Click
|
OnClick = CheckBox4Click
|
||||||
TabOrder = 5
|
TabOrder = 5
|
||||||
end
|
end
|
||||||
object CheckBox5: TCheckBox
|
object CheckBox5: TCheckBox
|
||||||
Left = 6
|
Left = 6
|
||||||
Height = 17
|
Height = 22
|
||||||
Top = 84
|
Top = 84
|
||||||
Width = 119
|
Width = 148
|
||||||
Caption = 'ShowColumnHeaders'
|
Caption = 'ShowColumnHeaders'
|
||||||
Checked = True
|
Checked = True
|
||||||
OnClick = CheckBox5Click
|
OnClick = CheckBox5Click
|
||||||
@ -151,26 +151,75 @@ object Form1: TForm1
|
|||||||
TabOrder = 6
|
TabOrder = 6
|
||||||
end
|
end
|
||||||
object HideSelection: TCheckBox
|
object HideSelection: TCheckBox
|
||||||
Left = 91
|
Left = 97
|
||||||
Height = 17
|
Height = 22
|
||||||
Top = 4
|
Top = 4
|
||||||
Width = 82
|
Width = 104
|
||||||
Caption = 'HideSelection'
|
Caption = 'HideSelection'
|
||||||
Checked = True
|
Checked = True
|
||||||
OnChange = HideSelectionChange
|
OnChange = HideSelectionChange
|
||||||
State = cbChecked
|
State = cbChecked
|
||||||
TabOrder = 7
|
TabOrder = 7
|
||||||
end
|
end
|
||||||
|
object ChBoxOwnerData: TCheckBox
|
||||||
|
Left = 6
|
||||||
|
Height = 22
|
||||||
|
Top = 249
|
||||||
|
Width = 88
|
||||||
|
Caption = 'OwnerData'
|
||||||
|
OnChange = ChBoxOwnerDataChange
|
||||||
|
TabOrder = 8
|
||||||
|
end
|
||||||
|
object lblSetCount: TLabel
|
||||||
|
Left = 10
|
||||||
|
Height = 17
|
||||||
|
Top = 281
|
||||||
|
Width = 55
|
||||||
|
Caption = 'SetCount'
|
||||||
|
Enabled = False
|
||||||
|
ParentColor = False
|
||||||
|
end
|
||||||
|
object OwnerDataCount: TSpinEdit
|
||||||
|
Left = 88
|
||||||
|
Height = 22
|
||||||
|
Top = 276
|
||||||
|
Width = 84
|
||||||
|
Enabled = False
|
||||||
|
MaxValue = 10000000
|
||||||
|
OnChange = OwnerDataCountChange
|
||||||
|
TabOrder = 9
|
||||||
|
Value = 2
|
||||||
|
end
|
||||||
|
object CheckBox6: TCheckBox
|
||||||
|
Left = 6
|
||||||
|
Height = 22
|
||||||
|
Top = 217
|
||||||
|
Width = 154
|
||||||
|
Caption = 'AutoWidthLastColumn'
|
||||||
|
OnChange = CheckBox6Change
|
||||||
|
TabOrder = 10
|
||||||
|
end
|
||||||
|
object CheckBox7: TCheckBox
|
||||||
|
Left = 97
|
||||||
|
Height = 22
|
||||||
|
Top = 28
|
||||||
|
Width = 81
|
||||||
|
Caption = 'ReadOnly'
|
||||||
|
Checked = True
|
||||||
|
OnChange = CheckBox7Change
|
||||||
|
State = cbChecked
|
||||||
|
TabOrder = 11
|
||||||
|
end
|
||||||
end
|
end
|
||||||
object Page1: TTabSheet
|
object Page1: TTabSheet
|
||||||
Caption = 'Items'
|
Caption = 'Items'
|
||||||
ClientHeight = 0
|
ClientHeight = 307
|
||||||
ClientWidth = 0
|
ClientWidth = 205
|
||||||
object Label6: TLabel
|
object Label6: TLabel
|
||||||
Left = 6
|
Left = 6
|
||||||
Height = 17
|
Height = 17
|
||||||
Top = 4
|
Top = 4
|
||||||
Width = 65
|
Width = 32
|
||||||
Caption = 'Index'
|
Caption = 'Index'
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
end
|
end
|
||||||
@ -178,7 +227,7 @@ object Form1: TForm1
|
|||||||
Left = 94
|
Left = 94
|
||||||
Height = 17
|
Height = 17
|
||||||
Top = 4
|
Top = 4
|
||||||
Width = 65
|
Width = 55
|
||||||
Caption = 'SubIndex'
|
Caption = 'SubIndex'
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
end
|
end
|
||||||
@ -186,7 +235,7 @@ object Form1: TForm1
|
|||||||
Left = 6
|
Left = 6
|
||||||
Height = 17
|
Height = 17
|
||||||
Top = 116
|
Top = 116
|
||||||
Width = 65
|
Width = 25
|
||||||
Caption = 'Text'
|
Caption = 'Text'
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
end
|
end
|
||||||
@ -194,7 +243,7 @@ object Form1: TForm1
|
|||||||
Left = 94
|
Left = 94
|
||||||
Height = 17
|
Height = 17
|
||||||
Top = 116
|
Top = 116
|
||||||
Width = 65
|
Width = 67
|
||||||
Caption = 'ImageIndex'
|
Caption = 'ImageIndex'
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
end
|
end
|
||||||
@ -240,7 +289,7 @@ object Form1: TForm1
|
|||||||
end
|
end
|
||||||
object Edit1: TEdit
|
object Edit1: TEdit
|
||||||
Left = 6
|
Left = 6
|
||||||
Height = 23
|
Height = 22
|
||||||
Top = 20
|
Top = 20
|
||||||
Width = 80
|
Width = 80
|
||||||
OnChange = Edit1Change
|
OnChange = Edit1Change
|
||||||
@ -249,7 +298,7 @@ object Form1: TForm1
|
|||||||
end
|
end
|
||||||
object Edit4: TEdit
|
object Edit4: TEdit
|
||||||
Left = 6
|
Left = 6
|
||||||
Height = 23
|
Height = 22
|
||||||
Top = 132
|
Top = 132
|
||||||
Width = 80
|
Width = 80
|
||||||
OnChange = Edit4Change
|
OnChange = Edit4Change
|
||||||
@ -258,7 +307,7 @@ object Form1: TForm1
|
|||||||
end
|
end
|
||||||
object Edit5: TEdit
|
object Edit5: TEdit
|
||||||
Left = 94
|
Left = 94
|
||||||
Height = 23
|
Height = 22
|
||||||
Top = 20
|
Top = 20
|
||||||
Width = 80
|
Width = 80
|
||||||
OnChange = Edit5Change
|
OnChange = Edit5Change
|
||||||
@ -267,7 +316,7 @@ object Form1: TForm1
|
|||||||
end
|
end
|
||||||
object Edit10: TEdit
|
object Edit10: TEdit
|
||||||
Left = 94
|
Left = 94
|
||||||
Height = 23
|
Height = 22
|
||||||
Top = 132
|
Top = 132
|
||||||
Width = 80
|
Width = 80
|
||||||
OnChange = Edit10Change
|
OnChange = Edit10Change
|
||||||
@ -277,8 +326,8 @@ object Form1: TForm1
|
|||||||
end
|
end
|
||||||
object Page2: TTabSheet
|
object Page2: TTabSheet
|
||||||
Caption = 'Columns'
|
Caption = 'Columns'
|
||||||
ClientHeight = 0
|
ClientHeight = 307
|
||||||
ClientWidth = 0
|
ClientWidth = 205
|
||||||
object Label1: TLabel
|
object Label1: TLabel
|
||||||
Left = 6
|
Left = 6
|
||||||
Height = 17
|
Height = 17
|
||||||
@ -414,7 +463,7 @@ object Form1: TForm1
|
|||||||
Height = 21
|
Height = 21
|
||||||
Top = 191
|
Top = 191
|
||||||
Width = 80
|
Width = 80
|
||||||
ItemHeight = 13
|
ItemHeight = 0
|
||||||
Items.Strings = (
|
Items.Strings = (
|
||||||
'taLeftJustify'
|
'taLeftJustify'
|
||||||
'taRightJustify'
|
'taRightJustify'
|
||||||
@ -436,28 +485,32 @@ object Form1: TForm1
|
|||||||
end
|
end
|
||||||
object ListView1: TListView
|
object ListView1: TListView
|
||||||
Left = 8
|
Left = 8
|
||||||
Height = 280
|
Height = 341
|
||||||
Top = 8
|
Top = 8
|
||||||
Width = 417
|
Width = 383
|
||||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||||
BorderWidth = 2
|
BorderWidth = 2
|
||||||
Columns = <
|
Columns = <
|
||||||
item
|
item
|
||||||
Caption = 'One'
|
Caption = 'One'
|
||||||
|
Width = 80
|
||||||
end
|
end
|
||||||
item
|
item
|
||||||
Caption = 'Two'
|
Caption = 'Two'
|
||||||
|
Width = 301
|
||||||
end>
|
end>
|
||||||
Items.LazData = {
|
Items.LazData = {
|
||||||
540000000200000000000000FFFFFFFFFFFFFFFF02000000050000004E657720
|
540000000200000000000000FFFFFFFFFFFFFFFF02000000050000004E657720
|
||||||
31050000005375622031050000005375622032FFFFFFFFFFFFFFFFFFFFFFFF00
|
31050000005375622031050000005375622032FFFFFFFFFFFFFFFFFFFFFFFF00
|
||||||
000000050000004E65772032FFFFFFFFFFFFFFFF
|
000000050000004E65772032FFFFFFFFFFFFFFFF
|
||||||
}
|
}
|
||||||
|
ReadOnly = True
|
||||||
ScrollBars = ssAutoBoth
|
ScrollBars = ssAutoBoth
|
||||||
SmallImages = ImageList1
|
SmallImages = ImageList1
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
ViewStyle = vsReport
|
ViewStyle = vsReport
|
||||||
OnColumnClick = ListView1ColumnClick
|
OnColumnClick = ListView1ColumnClick
|
||||||
|
OnData = ListView1Data
|
||||||
OnSelectItem = ListView1SelectItem
|
OnSelectItem = ListView1SelectItem
|
||||||
end
|
end
|
||||||
object ImageList1: TImageList
|
object ImageList1: TImageList
|
||||||
|
@ -6,7 +6,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls,
|
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls,
|
||||||
Buttons, StdCtrls, ExtCtrls;
|
Buttons, StdCtrls, ExtCtrls, Spin;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -24,6 +24,9 @@ type
|
|||||||
CheckBox3: TCheckBox;
|
CheckBox3: TCheckBox;
|
||||||
CheckBox4: TCheckBox;
|
CheckBox4: TCheckBox;
|
||||||
CheckBox5: TCheckBox;
|
CheckBox5: TCheckBox;
|
||||||
|
ChBoxOwnerData: TCheckBox;
|
||||||
|
CheckBox6: TCheckBox;
|
||||||
|
CheckBox7: TCheckBox;
|
||||||
HideSelection: TCheckBox;
|
HideSelection: TCheckBox;
|
||||||
ComboBox1: TComboBox;
|
ComboBox1: TComboBox;
|
||||||
ComboBox2: TComboBox;
|
ComboBox2: TComboBox;
|
||||||
@ -47,6 +50,7 @@ type
|
|||||||
Label12: TLabel;
|
Label12: TLabel;
|
||||||
Label13: TLabel;
|
Label13: TLabel;
|
||||||
Label14: TLabel;
|
Label14: TLabel;
|
||||||
|
lblSetCount: TLabel;
|
||||||
Label2: TLabel;
|
Label2: TLabel;
|
||||||
Label3: TLabel;
|
Label3: TLabel;
|
||||||
Label4: TLabel;
|
Label4: TLabel;
|
||||||
@ -60,17 +64,21 @@ type
|
|||||||
Page1: TTabSheet;
|
Page1: TTabSheet;
|
||||||
Page2: TTabSheet;
|
Page2: TTabSheet;
|
||||||
Page3: TTabSheet;
|
Page3: TTabSheet;
|
||||||
|
OwnerDataCount: TSpinEdit;
|
||||||
procedure Button1Click(Sender: TObject);
|
procedure Button1Click(Sender: TObject);
|
||||||
procedure Button2Click(Sender: TObject);
|
procedure Button2Click(Sender: TObject);
|
||||||
procedure Button3Click(Sender: TObject);
|
procedure Button3Click(Sender: TObject);
|
||||||
procedure Button4Click(Sender: TObject);
|
procedure Button4Click(Sender: TObject);
|
||||||
procedure Button5Click(Sender: TObject);
|
procedure Button5Click(Sender: TObject);
|
||||||
procedure Button6Click(Sender: TObject);
|
procedure Button6Click(Sender: TObject);
|
||||||
|
procedure ChBoxOwnerDataChange(Sender: TObject);
|
||||||
procedure CheckBox1Click (Sender: TObject );
|
procedure CheckBox1Click (Sender: TObject );
|
||||||
procedure CheckBox2Click (Sender: TObject );
|
procedure CheckBox2Click (Sender: TObject );
|
||||||
procedure CheckBox3Click(Sender: TObject);
|
procedure CheckBox3Click(Sender: TObject);
|
||||||
procedure CheckBox4Click(Sender: TObject);
|
procedure CheckBox4Click(Sender: TObject);
|
||||||
procedure CheckBox5Click(Sender: TObject);
|
procedure CheckBox5Click(Sender: TObject);
|
||||||
|
procedure CheckBox6Change(Sender: TObject);
|
||||||
|
procedure CheckBox7Change(Sender: TObject);
|
||||||
procedure ComboBox1Change (Sender: TObject );
|
procedure ComboBox1Change (Sender: TObject );
|
||||||
procedure ComboBox2Change(Sender: TObject);
|
procedure ComboBox2Change(Sender: TObject);
|
||||||
procedure ComboBox3Change(Sender: TObject);
|
procedure ComboBox3Change(Sender: TObject);
|
||||||
@ -87,7 +95,9 @@ type
|
|||||||
procedure Edit8Change(Sender: TObject);
|
procedure Edit8Change(Sender: TObject);
|
||||||
procedure HideSelectionChange(Sender: TObject);
|
procedure HideSelectionChange(Sender: TObject);
|
||||||
procedure ListView1ColumnClick(Sender: TObject; Column: TListColumn);
|
procedure ListView1ColumnClick(Sender: TObject; Column: TListColumn);
|
||||||
|
procedure ListView1Data(Sender: TObject; Item: TListItem);
|
||||||
procedure ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
|
procedure ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
|
||||||
|
procedure OwnerDataCountChange(Sender: TObject);
|
||||||
private
|
private
|
||||||
procedure ShowItemData;
|
procedure ShowItemData;
|
||||||
procedure ShowColumnData;
|
procedure ShowColumnData;
|
||||||
@ -108,18 +118,33 @@ implementation
|
|||||||
procedure TForm1.Button1Click(Sender: TObject);
|
procedure TForm1.Button1Click(Sender: TObject);
|
||||||
var
|
var
|
||||||
Item: TListItem;
|
Item: TListItem;
|
||||||
|
begin
|
||||||
|
if ListView1.OwnerData then
|
||||||
|
// OwnerDataCount.OnChange() triggers new items count.
|
||||||
|
OwnerDataCount.Value := ListView1.Items.Count + 1
|
||||||
|
else
|
||||||
begin
|
begin
|
||||||
Item := ListView1.Items.Insert(StrToIntDef(Edit1.Text, 0));
|
Item := ListView1.Items.Insert(StrToIntDef(Edit1.Text, 0));
|
||||||
Item.Caption := Format('Item %d', [ListView1.Items.Count]);
|
Item.Caption := Format('Item %d', [ListView1.Items.Count]);
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TForm1.Button2Click(Sender: TObject);
|
procedure TForm1.Button2Click(Sender: TObject);
|
||||||
var
|
var
|
||||||
Item: TListItem;
|
Item: TListItem;
|
||||||
|
Idx: Integer;
|
||||||
begin
|
begin
|
||||||
Item := ListView1.Items[StrToIntDef(Edit1.Text, 0)];
|
if ListView1.OwnerData then
|
||||||
|
OwnerDataCount.Value := ListView1.Items.Count - 1
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
Idx := StrToIntDef(Edit1.Text, 0);
|
||||||
|
if (Idx < 0) or (Idx > ListView1.Items.Count - 1) then
|
||||||
|
exit;
|
||||||
|
Item := ListView1.Items[Idx];
|
||||||
Item.Free;
|
Item.Free;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TForm1.Button3Click(Sender: TObject);
|
procedure TForm1.Button3Click(Sender: TObject);
|
||||||
var
|
var
|
||||||
@ -141,19 +166,65 @@ end;
|
|||||||
procedure TForm1.Button5Click(Sender: TObject);
|
procedure TForm1.Button5Click(Sender: TObject);
|
||||||
var
|
var
|
||||||
Item: TListItem;
|
Item: TListItem;
|
||||||
|
Idx: Integer;
|
||||||
begin
|
begin
|
||||||
Item := ListView1.Items[StrToIntDef(Edit1.Text, 0)];
|
Idx := StrToIntDef(Edit1.Text, 0);
|
||||||
|
if (Idx < 0) or (Idx > ListView1.Items.Count - 1) then
|
||||||
|
exit;
|
||||||
|
Item := ListView1.Items[Idx];
|
||||||
Item.Selected := True;
|
Item.Selected := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.Button6Click(Sender: TObject);
|
procedure TForm1.Button6Click(Sender: TObject);
|
||||||
var
|
var
|
||||||
Item: TListItem;
|
Item: TListItem;
|
||||||
|
Idx: Integer;
|
||||||
begin
|
begin
|
||||||
Item := ListView1.Items[StrToIntDef(Edit1.Text, 0)];
|
Idx := StrToIntDef(Edit1.Text, 0);
|
||||||
|
if (Idx < 0) or (Idx > ListView1.Items.Count - 1) then
|
||||||
|
exit;
|
||||||
|
Item := ListView1.Items[Idx];
|
||||||
Item.Focused := True;
|
Item.Focused := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.ChBoxOwnerDataChange(Sender: TObject);
|
||||||
|
var
|
||||||
|
B: Boolean;
|
||||||
|
AItem: TListItem;
|
||||||
|
begin
|
||||||
|
B := TCheckBox(Sender).Checked;
|
||||||
|
lblSetCount.Enabled := B;
|
||||||
|
OwnerDataCount.Enabled := B;
|
||||||
|
ListView1.BeginUpdate;
|
||||||
|
try
|
||||||
|
ListView1.Clear; // first clear all items because virtual and normal items are different classes
|
||||||
|
finally
|
||||||
|
ListView1.EndUpdate;
|
||||||
|
end;
|
||||||
|
ListView1.OwnerData := B;
|
||||||
|
ListView1.BeginUpdate;
|
||||||
|
try
|
||||||
|
if B then
|
||||||
|
ListView1.Items.Count := OwnerDataCount.Value
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
with ListView1 do
|
||||||
|
begin
|
||||||
|
AItem := Items.Add;
|
||||||
|
AItem.Caption := 'New 1';
|
||||||
|
AItem.ImageIndex := 0;
|
||||||
|
AItem.StateIndex := 0;
|
||||||
|
AItem.SubItems.Add('Sub 1');
|
||||||
|
|
||||||
|
AItem := Items.Add;
|
||||||
|
AItem.Caption := 'New 2';
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
ListView1.EndUpdate;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TForm1.CheckBox1Click(Sender: TObject);
|
procedure TForm1.CheckBox1Click(Sender: TObject);
|
||||||
var
|
var
|
||||||
Column: TListColumn;
|
Column: TListColumn;
|
||||||
@ -185,6 +256,16 @@ begin
|
|||||||
ListView1.ShowColumnHeaders := CheckBox5.Checked;
|
ListView1.ShowColumnHeaders := CheckBox5.Checked;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.CheckBox6Change(Sender: TObject);
|
||||||
|
begin
|
||||||
|
ListView1.AutoWidthLastColumn := TCheckBox(Sender).Checked;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.CheckBox7Change(Sender: TObject);
|
||||||
|
begin
|
||||||
|
ListView1.ReadOnly := TCheckBox(Sender).Checked;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TForm1.ComboBox1Change (Sender: TObject );
|
procedure TForm1.ComboBox1Change (Sender: TObject );
|
||||||
var
|
var
|
||||||
Column: TListColumn;
|
Column: TListColumn;
|
||||||
@ -214,7 +295,10 @@ var
|
|||||||
n, idx: Integer;
|
n, idx: Integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Item := ListView1.Items[StrToIntDef(Edit1.Text, 0)];
|
idx := StrToIntDef(Edit1.Text, 0);
|
||||||
|
if (idx < 0) or (idx > ListView1.Items.Count - 1) then
|
||||||
|
exit;
|
||||||
|
Item := ListView1.Items[idx];
|
||||||
|
|
||||||
for n := Item.SubItems.Count to ListView1.Columns.Count - 2 do
|
for n := Item.SubItems.Count to ListView1.Columns.Count - 2 do
|
||||||
Item.Subitems.Add('');
|
Item.Subitems.Add('');
|
||||||
@ -222,10 +306,10 @@ begin
|
|||||||
n := StrToIntDef(Edit5.Text, 0);
|
n := StrToIntDef(Edit5.Text, 0);
|
||||||
if n >= ListView1.Columns.Count then Exit;
|
if n >= ListView1.Columns.Count then Exit;
|
||||||
idx := StrToIntDef(Edit10.Text, -1);
|
idx := StrToIntDef(Edit10.Text, -1);
|
||||||
if n = 0
|
if n = 0 then
|
||||||
then Item.ImageIndex := idx
|
Item.ImageIndex := idx
|
||||||
else Item.SubitemImages[n - 1] := idx;
|
else
|
||||||
|
Item.SubitemImages[n - 1] := idx;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.Edit11Change(Sender: TObject);
|
procedure TForm1.Edit11Change(Sender: TObject);
|
||||||
@ -256,7 +340,10 @@ var
|
|||||||
Item: TListItem;
|
Item: TListItem;
|
||||||
n: Integer;
|
n: Integer;
|
||||||
begin
|
begin
|
||||||
Item := ListView1.Items[StrToIntDef(Edit1.Text, 0)];
|
n := StrToIntDef(Edit1.Text, 0);
|
||||||
|
if (n < 0) or (n > ListView1.Items.Count - 1) then
|
||||||
|
exit;
|
||||||
|
Item := ListView1.Items[n];
|
||||||
for n := Item.SubItems.Count to ListView1.Columns.Count - 2 do
|
for n := Item.SubItems.Count to ListView1.Columns.Count - 2 do
|
||||||
Item.Subitems.Add('');
|
Item.Subitems.Add('');
|
||||||
n := StrToIntDef(Edit5.Text, 0);
|
n := StrToIntDef(Edit5.Text, 0);
|
||||||
@ -306,6 +393,21 @@ begin
|
|||||||
Edit5.Text := IntToStr(Column.Index);
|
Edit5.Text := IntToStr(Column.Index);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.ListView1Data(Sender: TObject; Item: TListItem);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
if (ListView1.ColumnCount > 0) then
|
||||||
|
begin
|
||||||
|
Item.Caption := 'OwnerData item '+IntToStr(Item.Index);
|
||||||
|
Item.ImageIndex := -1;
|
||||||
|
Item.StateIndex := -1;
|
||||||
|
for i := 1 to ListView1.ColumnCount - 1 do
|
||||||
|
Item.SubItems.Add('OwnerData subitem ['+IntToStr(Item.Index)+','+IntToStr(i)+']');
|
||||||
|
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
|
procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
|
||||||
var
|
var
|
||||||
subIdx: Integer;
|
subIdx: Integer;
|
||||||
@ -314,12 +416,24 @@ begin
|
|||||||
Edit1.Text := IntToStr(Item.Index);
|
Edit1.Text := IntToStr(Item.Index);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.OwnerDataCountChange(Sender: TObject);
|
||||||
|
begin
|
||||||
|
if not ListView1.OwnerData then
|
||||||
|
exit;
|
||||||
|
ListView1.BeginUpdate;
|
||||||
|
ListView1.Items.Count := TSpinEdit(Sender).Value;
|
||||||
|
ListView1.EndUpdate;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TForm1.ShowItemData;
|
procedure TForm1.ShowItemData;
|
||||||
var
|
var
|
||||||
Item: TListItem;
|
Item: TListItem;
|
||||||
idx: Integer;
|
idx: Integer;
|
||||||
begin
|
begin
|
||||||
Item := ListView1.Items[StrToIntDef(Edit1.Text, 0)];
|
idx := StrToIntDef(Edit1.Text, 0);
|
||||||
|
if (idx < 0) or (idx > ListView1.Items.Count - 1) then
|
||||||
|
exit;
|
||||||
|
Item := ListView1.Items[idx];
|
||||||
|
|
||||||
idx := StrToIntDef(Edit5.Text, 0);
|
idx := StrToIntDef(Edit5.Text, 0);
|
||||||
if idx = 0
|
if idx = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user