473,387 Members | 1,290 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ListView with file extension icons

I'm doing a kind of file explorer with some additional funcionalities. The
problem is that I'm not able to draw file extension icons in a ListView. I
know how obtain icons, but when I try to draw file icon, this isn't showed.

I tried to do by two ways:

1- By creating the ListViewItem and adding it to ListView, then I get
rectangle of icon element and paint a new icon in rectangle coordenates. I'm
able to view icons while they are drawn, but when all ListViewItems has been
added, icons dissapear and each ListViewItem hasn't icon or isn't visible.

2- Adding a void ImageList and inserting icons dinamically. While file list
is read, I check if file icon exists in ImageList, if icon exists I do
nothing, else I insert icon in ImageList. After I get index of image
inserted and set to ListViewItem ImageIndex attribute. When I execute a
System.NotSupportedException is thrown at line 08 of following code:

01. foreach(System.IO.FileInfo fi in di.GetFiles())
02. {

03. System.Drawing.Icon ico;

04. System.Drawing.Image ima;

05. lvi=new ListViewItem(fi.Name);

06. ico=ExtractIconClass.GetIconImage(fi.FullName);

07. ima=ico.ToBitmap();

08. if(!imgIcon.Images.Contains(ima))

09. {

10. imgIcon.Images.Add(ico.ToBitmap());

11. }

12. lvi.ImageIndex=imgIcon.Images.IndexOf(ico.ToBitmap ());

13. lv.Items.Add(lvi); //addListViewItem to ListView

14. }

I don't know what is the problem. I prefer first method or if somebody knows
better I would like it know.

Thanks.
Victor

Nov 16 '05 #1
1 15006
Hi,

Wouldn't it be better to cache all known icons beforehand in the ImageList?
I believe they all are enumerated in the registry, and it should also
improve the performance of populating the file list as you won't need to
load the icons on the fly.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Víctor" <vi******@vodafone.es> wrote in message
news:et**************@TK2MSFTNGP15.phx.gbl...
I'm doing a kind of file explorer with some additional funcionalities. The
problem is that I'm not able to draw file extension icons in a ListView. I
know how obtain icons, but when I try to draw file icon, this isn't
showed.

I tried to do by two ways:

1- By creating the ListViewItem and adding it to ListView, then I get
rectangle of icon element and paint a new icon in rectangle coordenates.
I'm
able to view icons while they are drawn, but when all ListViewItems has
been
added, icons dissapear and each ListViewItem hasn't icon or isn't visible.

2- Adding a void ImageList and inserting icons dinamically. While file
list
is read, I check if file icon exists in ImageList, if icon exists I do
nothing, else I insert icon in ImageList. After I get index of image
inserted and set to ListViewItem ImageIndex attribute. When I execute a
System.NotSupportedException is thrown at line 08 of following code:

01. foreach(System.IO.FileInfo fi in di.GetFiles())
02. {

03. System.Drawing.Icon ico;

04. System.Drawing.Image ima;

05. lvi=new ListViewItem(fi.Name);

06. ico=ExtractIconClass.GetIconImage(fi.FullName);

07. ima=ico.ToBitmap();

08. if(!imgIcon.Images.Contains(ima))

09. {

10. imgIcon.Images.Add(ico.ToBitmap());

11. }

12. lvi.ImageIndex=imgIcon.Images.IndexOf(ico.ToBitmap ());

13. lv.Items.Add(lvi); //addListViewItem to ListView

14. }

I don't know what is the problem. I prefer first method or if somebody
knows
better I would like it know.

Thanks.
Victor


Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Garet Cammer | last post by:
I am writing a VB 6.0 program similar to Windows Explorer, which has a tree view and a list view to select directories and files. I would like to associate an icon with each file, according to the...
3
by: Ian | last post by:
Hi, I've been trying to create a listview and treeview with icons. You would think it's a pretty straight forward task. API documentation states you simply assign an ImageList - that's been...
3
by: scoobydoo | last post by:
hi, I have a problem displaying icons at the right colour depthin a ListView. I've made an icon file, (using IconWorkshop 5), it has 3 icons within it. A 32x32 32bpp XP style icon, a 32x32...
3
by: MikeY | last post by:
Hopefully someone can help me on this. I am using C#, making Windows forms. I have created a listView with checkbox's. I have enabled the checkboxes under the properties, and all the data,...
2
by: MikeY | last post by:
Hi all, I am coding window forms in C#. My problem is this: I have created a "Check ListView" or a 'ListView' with checkbox's. I have populated the it with my files from my folders, mps, txt,...
1
by: Sander R | last post by:
Hi, I can't get the the listview (or toolbar) to display the alpha channels of XP icons correctly. I have a manifest file for my binary, and the xp theme is applied correctly. It is only the...
4
by: Ira Siyal | last post by:
Hi I had a project in VB6 which I upgraded to VB.NET recently. In the app, I am facing some issue with listview control. In the earlier app, I have set the Icons in listview through an...
1
by: Richard | last post by:
If I'm to make a Listview with a list of files, then how can i get the associated icon to match the file?? Meaning I need the Windows Explorer icons to be the same as in my listview. I can...
0
by: twoSeven | last post by:
hi, Here is what i want to do. I am making a file and folder browser similar to Windows Explorer with a treeview and listview.. In that, i get icons and thumbnails of a particular file/folder from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.