Display large and small ListView icons in C#

[ListView icons]

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 32×32 pixel images and the other contains 64×64 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,
    EventArgs e)
    switch (cboStyle.Text)
        case "Large Icons":
            lvwBooks.View = View.LargeIcon;
        case "Small Icons":
            lvwBooks.View = View.SmallIcon;
        case "List":
            lvwBooks.View = View.List;
        case "Tile":
            lvwBooks.View = View.Tile;
        case "Details":
            lvwBooks.View = View.Details;

To learn about other details, such as how the program creates the ListView items, download the example and look at the code.

Download Example   Follow me on Twitter   RSS feed   Donate

This entry was posted in controls and tagged , , , , , , , , , , , , , , . Bookmark the permalink.

3 Responses to Display large and small ListView icons in C#

  1. jdnp says:

    This is relay good and simple
    thank you.How can I do this for items from database.how to map photo ?any idea ?

  2. Rod Stephens says:

    Sure. You can load images into the ImageList controls from the database at run time. Give each image a string key value. Then when you create each of the ListView items, give it the key for the image you want to use.

    I’ll post an example in a few days so check back. Or if you want the example sooner but without the description (I haven’t written it yet), email me.

  3. Pingback: Create ListView icons at run time in C# - C# HelperC# Helper

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.