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. Listview, multiple import?

Listview, multiple import?

Scheduled Pinned Locked Moved C#
helptutorialquestion
3 Posts 3 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.
  • J Offline
    J Offline
    jas0n23
    wrote on last edited by
    #1

    Hey everybody! I was just wondering if anybody knows an easy and quick way of importing multiple files into a listview control? I know how to import just a single file. But, I'm not quite sure how to import multiple ones, and I couldn't find anything on google or msdn, it seems as though when i actually need help, google is NOT my friend lol. regards, j.t. :-D

    j.t.

    D L 2 Replies Last reply
    0
    • J jas0n23

      Hey everybody! I was just wondering if anybody knows an easy and quick way of importing multiple files into a listview control? I know how to import just a single file. But, I'm not quite sure how to import multiple ones, and I couldn't find anything on google or msdn, it seems as though when i actually need help, google is NOT my friend lol. regards, j.t. :-D

      j.t.

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      jay_t55 wrote:

      importing multiple files into a listview

      A ListView doesn't have a collection of files, it has a ListView.ListViewItemCollection to which you can add ListViewItem instances. Each of those instances also has a ListViewItem.ListViewSubItemCollection. To add multiple items to your ListView at once, use the AddRange method and pass either an array of ListViewItems or a ListView.ListViewItemCollection. The same theory applies to each item's sub items. How you create the above from a given file and it's attributes is up to you. Personally I would create a ToListViewItems method that takes a collection of files as a parameter.

      Dave
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
      Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

      1 Reply Last reply
      0
      • J jas0n23

        Hey everybody! I was just wondering if anybody knows an easy and quick way of importing multiple files into a listview control? I know how to import just a single file. But, I'm not quite sure how to import multiple ones, and I couldn't find anything on google or msdn, it seems as though when i actually need help, google is NOT my friend lol. regards, j.t. :-D

        j.t.

        L Offline
        L Offline
        Lev Danielyan
        wrote on last edited by
        #3

        Here is how it can be done using LINQ:

        DirectoryInfo dir = new DirectoryInfo(@"c:\temp");
        FileInfo[] files = dir.GetFiles();

        var fileList = from file in files
        select new ListViewItem(file.FullName) { Tag = file };

        listView1.Items.AddRange(fileList.ToArray());

        Regards, Lev

        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