Listview, multiple import?
-
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.
-
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.
jay_t55 wrote:
importing multiple files into a listview
A
ListView
doesn't have a collection of files, it has aListView.ListViewItemCollection
to which you can addListViewItem
instances. Each of those instances also has aListViewItem.ListViewSubItemCollection
. To add multiple items to yourListView
at once, use the AddRange method and pass either an array ofListViewItem
s or aListView.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) -
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.
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