how to show file icons in list view control?
-
Hi, all. I study C# programming about list view control. and I would like to show file icons on the list view control, when I drag & drop some files. I could show file paths on list view control though. but I can't show file icons.
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string file in files) { Icon ico = Icon.ExtractAssociatedIcon(@file); Image img = ico.ToBitmap(); ListViewItem lvi = new ListViewItem(); lvi.Text = ""; lvi.ImageList.Images.Add(img);
// this line has an error. // I would like to show file icons on this list view control , when I drag & drop some files. // I can show file paths when I drag & drop on the control though.listView1.Items.Add(file); }
Thanks.:) -
Hi, all. I study C# programming about list view control. and I would like to show file icons on the list view control, when I drag & drop some files. I could show file paths on list view control though. but I can't show file icons.
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string file in files) { Icon ico = Icon.ExtractAssociatedIcon(@file); Image img = ico.ToBitmap(); ListViewItem lvi = new ListViewItem(); lvi.Text = ""; lvi.ImageList.Images.Add(img);
// this line has an error. // I would like to show file icons on this list view control , when I drag & drop some files. // I can show file paths when I drag & drop on the control though.listView1.Items.Add(file); }
Thanks.:)Whats the error ?
Icon.ExtractAssociatedIcon(@file);
Remove @
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
-
Whats the error ?
Icon.ExtractAssociatedIcon(@file);
Remove @
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
Originally, I did that way. even though I removed @, an error occured. like this: First exception of 'System.NullReferenceException' format is occured from StackDocklet.exe.
-
Originally, I did that way. even though I removed @, an error occured. like this: First exception of 'System.NullReferenceException' format is occured from StackDocklet.exe.
Perhaps the ImageList is null? The times that I've used file icons in a ListView, I added the images to the ImageList, then set the image index of a ListViewItem accordingly. Of course, you need to set the ListView.ImageList property to the aforementioned ImageList
-
Originally, I did that way. even though I removed @, an error occured. like this: First exception of 'System.NullReferenceException' format is occured from StackDocklet.exe.
that mean 'StackDocklet.exe' do not have any icon...
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
-
Hi, all. I study C# programming about list view control. and I would like to show file icons on the list view control, when I drag & drop some files. I could show file paths on list view control though. but I can't show file icons.
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string file in files) { Icon ico = Icon.ExtractAssociatedIcon(@file); Image img = ico.ToBitmap(); ListViewItem lvi = new ListViewItem(); lvi.Text = ""; lvi.ImageList.Images.Add(img);
// this line has an error. // I would like to show file icons on this list view control , when I drag & drop some files. // I can show file paths when I drag & drop on the control though.listView1.Items.Add(file); }
Thanks.:)lsh486love wrote:
lvi.ImageList.Images.Add(img);
the ImageList value is null. You can try this:
string s= "1.txt"; Icon i = Icon.ExtractAssociatedIcon( s ); ImageList imageList = new ImageList(); imageList.Images.Add(i); this.listView1.SmallImageList = imageList; this.listView1.Items.Add(new ListViewItem(s, 0));
Hope this will help you~:) I Love KongFu~