I have a ListView capable of displaying files in all available views (Large Icon, Small Icon, Tile, List, Details).
Now I am wondering how to properly use the SmallImagelist and LargeImagelist for the small and large icons...
The ListView is actually a modified listview (inheriting from ListView), using a modified ListViewItemCollection.
In this custom ListViewItemCollection I use the Add override function to add a few details to my ListViewItem:
Public Overrides Function Add(ByVal value As System.Windows.Forms.ListViewItem) As System.Windows.Forms.ListViewItem
Dim file As
clsTexture = TryCast(
IsNot Nothing Then
Dim str As String
str = "Yes"
str = "No"
is just a class inheriting from ListViewItem that:
- Hosts a LargeIcon and a LargeIconPtr property
- Hosts a SmallIcon and a SmallIconPtr property
The LargeIcon and SmallIcon icons are determined using the SHFileInfo API (or something... not really relevent I think) which gets the icons associated with the filetype of the file.
The SHFileInfo API uses the Handle (pointer?) of a System Icon to determine the icon. I had the idea to use that Handle (ToString) as the Key for the Image in the Imagelist, so that I am not adding 50000 of the same icons to a single list. So I use the LargeIconPtr and SmallIconPtr properties as the Handle.
As you can see I therefore now have a LargeIcon + its Handle, which I store in the LargeImageList with the Key as the Handle, and I also have a SmallIcon + its Handle, which I store in the SmallImagelist with the Key as the Handle.
The obvious problem now: how to set the ImageKey property of the ListViewItem ( = file)...??
If can either set it to the handle.ToString of the LargeIcon handle or the SmallIcon handle...
Are they always the same?
Or am I going to run into trouble just setting it to the LargeIcon handle (or SmallIcon handle for that matter), because they might be different, resulting in a different icon in the Large Icons view then in the Small Icons view...??
Suppose for example we have an icon where the SmallIcon looks different than the LargeIcon (more detail for example). Suppose the SmallIconPtr = 0, and the LargeIconPtr = 1.
If I now set the ImageKey to "1", it will use the LargeIcon when the ListView uses the LargeImagelist (depends on its View), but it will use the WRONG ICON when the SmallImagelist is used (because there may be, and probably is, a very different icon associated with key "1" in the SmallImagelist!!)
How can I get around this problem?
I realize it is a pretty complex post to read and will probably not get very many answers, but I really want to make the most of my Listviews...
Of course, one work around is to just always use the LargeIcon which then gets scaled down automatically when the SmallImagelist is used but I am pretty sure there are icons that are very different in Large or Small view...