Title: Display large and small ListView icons in C#
You can display two sizes of ListView icons. When the control's View property is LargeIcon or Tile, the control displays large icons. When the View property is SmallIcon, List, or Details, the control displays small icons.
The control gets its icons from two ImageList components.
To make a ListView control display icons, follow these steps:
- Add two ImageList components to the form.
- Set the ImageList controls' ImageSize properties to the sizes of the images they will contain. In this example, one ImageList contains 32x32 pixel images and the other contains 64x64 pixel images. (All of the images in a particular ImageList should have the same size.)
- Set the ImageList controls' ColorDepth properties to the color depth used by the images. In this example, both ImageList controls contain images that use 32-bit color, so their ColorDepth properties are set to Depth32bit.
- Set the ListView control's SmallImageList and LargeImageList properties to the two ImageList controls.
- Add the images to the ImageList controls.
- When you add an item to the ListView, set its ImageIndex property to the index of the item's image in the ImageList controls. Each item has a single ImageIndex property, so its small and large images must have the same indices in the two ImageList controls.
- Make the program set the ListView control's View property as desired.
The example program uses the following code to set the ListView control's View property when you select a new view from the combo box.
// Change the ListView's display style.
private void cboStyle_SelectedIndexChanged(object sender,
case "Large Icons":
lvwBooks.View = View.LargeIcon;
case "Small Icons":
lvwBooks.View = View.SmallIcon;
lvwBooks.View = View.List;
lvwBooks.View = View.Tile;
lvwBooks.View = View.Details;
Download the example to experiment with it and to see additional details.