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;
顺便说一句,您可以稍微简化代码(with
不过要小心!):
with sListView2.Items.Add do
begin
Caption := sListbox2.Items[i];
SubItems.Add(test');
ImageIndex := 1;
end;