Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to show file icons in list view control?

how to show file icons in list view control?

Scheduled Pinned Locked Moved C#
csharphelptutorialquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lsh486love
    wrote on last edited by
    #1

    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.:)

    X D 2 Replies Last reply
    0
    • L lsh486love

      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.:)

      X Offline
      X Offline
      Xmen Real
      wrote on last edited by
      #2

      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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

      L 1 Reply Last reply
      0
      • X Xmen Real

        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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

        L Offline
        L Offline
        lsh486love
        wrote on last edited by
        #3

        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.

        0 X 2 Replies Last reply
        0
        • L lsh486love

          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.

          0 Offline
          0 Offline
          0x3c0
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • L lsh486love

            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.

            X Offline
            X Offline
            Xmen Real
            wrote on last edited by
            #5

            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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

            1 Reply Last reply
            0
            • L lsh486love

              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.:)

              D Offline
              D Offline
              Dragonfly_Lee
              wrote on last edited by
              #6

              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~

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups