unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.ComCtrls,
Winapi.CommCtrl,
Vcl.StdCtrls,
System.ImageList,
Vcl.ImgList;
type
TForm1 =
class(TForm)
ListView1: TListView;
Button1: TButton;
ImageList1: TImageList;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
Checked: BOOL;
procedure SetLVSubImages(LV: TListView;
Index, Column: Integer;
Image: Integer; SubImagesOn: Bool);
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Checked :=
Not Checked;
if Checked
then
SetLVSubImages(ListView1, 3, 2, 1, True)
else
SetLVSubImages(ListView1, 3, 2, 0, True)
end;
procedure TForm1.FormCreate(Sender: TObject);
var IntI: Integer;
begin
for IntI := 0
to 2
do
ListView1.Column[IntI].Width := 100;
end;
procedure TForm1.SetLVSubImages(LV: TListView;
Index, Column, Image: Integer;
SubImagesOn: Bool);
var
lvStyle: DWORD;
LV_Item: TLVItem;
begin
lvStyle := SendMessage(LV.Handle, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
If SubImagesOn
Then
lvStyle := lvStyle
or LVS_EX_SUBITEMIMAGES
else
lvStyle := lvStyle
and Not LVS_EX_SUBITEMIMAGES;
SendMessage(LV.Handle, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, lvStyle);
If SubImagesOn
Then
begin
LV_Item.mask := LVIF_IMAGE;
LV_Item.iSubItem := Column;
LV_Item.iItem :=
Index - 1;
LV_Item.iImage := Image;
end;
SendMessage(LV.Handle, LVM_SETITEM, (
Index - 1), Integer(@LV_Item));
LV.Refresh;
end;
end.