2

I have added icons in a imageList via using this code in the listview. Now I want them to be displayed whenever the list view of certain directory is shown.

My question is:

What changes would I need to make in imagelist1 control? And how to call imagelist1 in the code?

imageList1.Images.Add(
    BlackFox.Win32.Icons.IconFromExtensionShell(
        ".*", 
        BlackFox.Win32.Icons.SystemIconSize.Small));

//lv.ImageIndex = 1;
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
engineer41
  • 81
  • 4
  • 15

1 Answers1

1

If I understand you correctly you want to display the icons in the ImageList together with the corresponding files in the ListView. To do this you only need to point the SmallImageList or LargeImageList attribute of your ListView object to the ImageList (depending on the icon display mode your ListView uses).

private void UpdateListView() {
   ImageList IconList = new ImageList();

   IconList.Images.Add(
        BlackFox.Win32.Icons.IconFromExtensionShell(".*",
        BlackFox.Win32.Icons.SystemIconSize.Small));

   YourListview.SmallImageList = IconList;

   //Add the items to your Listview                

}

Don't forget to assign the icons in the ImageList to the items in the ListView:

MyListItem.ImageIndex = 0;

or

MyListItem.ImageKey = "MyImageName";

or add them right away when you add your ListItems:

ListViewItem MyListItem= new ListViewItem("ItemName", "MyImageName");
ListViewItem MyListItem2= new ListViewItem("ItemName2", int ImageIndex);
Lennart
  • 9,657
  • 16
  • 68
  • 84