views:

380

answers:

1

I currently have a listview and I want to add an appropriate icon to each entry.

I have created an icon within the Project resources and called it 'errorIcon.ico'. How can I reference this icon/resource and use it within a listview?

+1  A: 

First you need to create an ImageList instance, see http://msdn.microsoft.com/en-us/library/system.windows.forms.imagelist.aspx (just drop it on your form/user control). Use the properties view to upload your icons to the image list.

Then, assign the image list to every ListViewItem (listViewItem.ImageList = imageList) and set the icon index (listViewItem.ImageIndex = 0)

Take a look at the remarks here for more information: http://msdn.microsoft.com/en-us/library/system.windows.forms.listviewitem.imageindex.aspx

Grzenio