[C# Helper]
Index Books FAQ Contact About Rod
[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[Beginning Software Engineering]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Display large and small ListView icons in C#

[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, EventArgs e) { switch (cboStyle.Text) { case "Large Icons": lvwBooks.View = View.LargeIcon; break; case "Small Icons": lvwBooks.View = View.SmallIcon; break; case "List": lvwBooks.View = View.List; break; case "Tile": lvwBooks.View = View.Tile; break; case "Details": lvwBooks.View = View.Details; break; } }

Download the example to experiment with it and to see additional details.

© 2009-2022 Rocky Mountain Computer Consulting, Inc. All rights reserved.