TImageList.ImageIndex
是一個整數,您需要正確設置它,並且要撥打AddIcon
您需要提供一個TIcon
。
如果你已經擁有它的TImageList
,只需設置TListView.ImageIndex
到該圖像的正確指標:
// Assign an image from the ImageList by index
test.ImageIndex := 1; // The second image in the ImageList
或者,如果你沒有一個現有的圖標TImageList
和需要添加一個,將其添加和存儲從AddIcon
返回值:
// Create a new TIcon, load an icon from a disk file, and
// add it to the ImageList, and set the TListView.ImageIndex
// to the new icon's index.
Ico := TIcon.Create;
try
Ico.LoadFromFile(SomeIconFileName);
test.ImageIndex := ImageList1.Add(Ico);
finally
Ico.Free;
end;
BTW,您可以簡化代碼略(小心with
,雖然!):
with sListView2.Items.Add do
begin
Caption := sListbox2.Items[i];
SubItems.Add(test');
ImageIndex := 1;
end;
感謝您的幫助。 – 14K