ListViewItem.ImageIndex 属性

定义

获取或设置为该项显示的图像的索引。Gets or sets the index of the image that is displayed for the item.

public:
 property int ImageIndex { int get(); void set(int value); };
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.NoneExcludedImageIndexConverter))]
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ImageIndexConverter))]
public int ImageIndex { get; set; }
member this.ImageIndex : int with get, set
Public Property ImageIndex As Integer

属性值

ImageList 中为该项显示的图像的从零开始的索引。The zero-based index of the image in the ImageList that is displayed for the item. 默认值为 -1。The default is -1.

属性

异常

指定的值小于 -1。The value specified is less than -1.

注解

此属性的值取决于ImageList属性的值。The value of this property depends on the value of the ImageList property. 根据与项View关联的ListView控件的属性的当前值, 该项使用的不SmallImageListImageList是在LargeImageList属性中指定的值, 也ListView可以是控件。Depending on the current value of the View property of the ListView control associated with the item, the ImageList used by the item could be one specified in the LargeImageList property or the SmallImageList property of the ListView control. LargeIcon SmallImageList ImageList ImageList如果将View属性设置为LargeImageList , 则使用属性中指定的; 否则, 将使用属性中指定的。If the View property is set to LargeIcon, the ImageList specified in the LargeImageList property is used; otherwise, the ImageList specified in the SmallImageList property is used. ImageList指定的SmallImageList中定义的图像应与LargeImageList属性中ImageList指定的中的图像具有相同的索引位置。The images defined in the ImageList specified in the SmallImageList should have the same index positions as the images in the ImageList specified in the LargeImageList property. 如果两个ImageList控件的索引位置相同, 则可以ImageIndex为属性设置单个索引值, 并显示相应的图像, 而不考虑ListView控件的View属性的值。If the index positions are the same for both ImageList controls, you can set a single index value for the ImageIndex property and the appropriate image will be displayed regardless of the value of the View property of the ListView control. ImageKeyImageIndex属性是互斥的, 也就是说, 如果已设置, 则会忽略另一个。The ImageKey and ImageIndex properties are mutually exclusive, meaning if one is set, the other is ignored. 此外, 如果设置ImageKey属性ImageIndex , 则属性会自动设置为-1。Furthermore, if you set the ImageKey property, the ImageIndex property is automatically set to -1. 或者, 如果设置ImageIndex了属性ImageKey , 则会自动将设置为空字符串 ("")。Alternatively, if you set the ImageIndex property, the ImageKey is automatically set to an empty string ("").

适用于

另请参阅