8.14 Using ImageLists in a ListView Control

 <  Day Day Up  >  

8.14 Using ImageList s in a ListView Control

You want to assign different images to the items in a ListView control.


Technique

The first step to assign an image list to a ListView control is to create an ImageList control. Drag and drop an ImageList control from the form designer toolbox onto your Windows Form. To add images to the ImageList , invoke the ImageList editor by accessing the edit button within the Images collection. To add an image within the editor, click on the Add button and browse to an image file.

When you finish adding images to the ImageList , associate the ImageList with the ListView by selecting a value from the drop-down lists in the SmallImageList and LargeImageList properties. You use the SmallImageList property when the ListView is in the SmallIcon , List , and Detail view modes, and you use the LargeImageList property with the LargeIcon view mode. The next recipe fully explains these modes. You can also specify a StateImageList , which is used when an application-defined state changes on an item. For instance, if the CheckBoxes property is true and a StateImageList is specified, the check boxes that normally appear are replaced by the images contained within the StateImageList.

Comments

A ListView control has the ability to display items as text, as an image, or both. An ImageList control is a nonvisual control used to hold information about a collection of images. Methods are available in the Images collection of the ImageList to add or remove individual images as well as obtain information about each image.

Because a ListView contains four separate view modes, it needs to be able to display both small and large images. Although the documentation mentions no defined image size , it is best to use images that are 16 x 16 for small images and 32 x 32 for large images. When creating images for a ListView , you should strive to create images that provide some sort of additional information about the item type the image represents. For instance, when viewing a list of files in Windows Explorer, you see icons that provide additional information about a file type that a filename cannot provide, assuming , of course, that you are not a walking encyclopedia of file extensions. If you are using a ListView and associated images for the control simply for aesthetic reasons, then you might want to rethink the design or at least limit the different views that the ListView displays.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net