Breyta

Deila með


ListViewItem.ImageIndex Property

Definition

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.ImageIndexConverter))]
public int ImageIndex { get; set; }
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.NoneExcludedImageIndexConverter))]
public int ImageIndex { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ImageIndexConverter))>]
member this.ImageIndex : int with get, set
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.NoneExcludedImageIndexConverter))>]
member this.ImageIndex : int with get, set
Public Property ImageIndex As Integer

Property Value

The zero-based index of the image in the ImageList that is displayed for the item. The default is -1.

Attributes

Exceptions

value is less than -1.

Remarks

The value of this property depends on the value of the ImageList property. 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. 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. The images defined in the ImageList specified in the SmallImageList property should have the same index positions as the images in the ImageList specified in the LargeImageList property. 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.

ImageKey and ImageIndex are mutually exclusive, meaning if one is set, the other is set to an invalid value and ignored. If you set the ImageKey property, the ImageIndex property is automatically set to -1. Alternatively, if you set the ImageIndex property, the ImageKey is automatically set to an empty string ("").

If the ImageList property value is changed to null, the ImageIndex property returns its default value, -1. However, the assigned ImageIndex value is retained internally and used when another ImageList object is assigned to the ImageList property. If the new ImageList assigned to the ImageList property has an ImageList.ImageCollection.Count property value that is less than or equal to the value assigned to the ImageIndex property minus one (to account for the collection being a zero-based index), the ImageIndex property value is adjusted to one less than the Count property value. For example, consider a button control whose ImageList has three images and whose ImageIndex property is set to 2. If a new ImageList that has only two images is assigned to the button, the ImageIndex value changes to 1.

Applies to

See also