如何:显示 Windows 窗体 ListView 控件的图标
更新:2007 年 11 月
Windows 窗体 ListView 控件可显示三个图像列表中的图标。“List”视图、“Details”视图和“SmallIcon”视图显示 SmallImageList 属性中指定的图像列表里的图像。“LargeIcon”视图显示 LargeImageList 属性中指定的图像列表里的图像。列表视图还可在大图标或小图标旁显示 StateImageList 属性中设置的一组附加图标。有关图像列表的更多信息,请参见 ImageList 组件(Windows 窗体) 和 如何:使用 Windows 窗体 ImageList 组件添加或移除图像。
在列表视图中显示图像
将相应的属性(SmallImageList、LargeImageList 或 StateImageList)设置为想要使用的现有 ImageList 组件。
这些属性可在设计器中使用“属性”窗口进行设置,也可在代码中设置。
ListView1.SmallImageList = ImageList1
listView1.SmallImageList = imageList1;
listView1.set_SmallImageList(imageList1);
为每个具有关联图标的列表项设置 ImageIndex 或 StateImageIndex 属性。
这些属性可在代码中设置,或在“ListViewItem 集合编辑器”中进行设置。若要打开“ListViewItem 集合编辑器”,请在“属性”窗口中,单击 Items 属性旁的省略号按钮 ()。
' Sets the first list item to display the 4th image. ListView1.Items(0).ImageIndex = 3
// Sets the first list item to display the 4th image. listView1.Items[0].ImageIndex = 3;
// Sets the first list item to display the 4th image. listView1.get_Items().get_Item(0).set_ImageIndex(3);
请参见
任务
如何:使用 Windows 窗体 ListView 控件添加和移除项
如何:向 Windows 窗体 ListView 控件中添加列
如何:向 TreeView 或 ListView 控件添加自定义信息(Windows 窗体)