Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


Ever had trouble saving ListViewItem data? filter_list
Author
Message
Ever had trouble saving ListViewItem data? #1
Not much else going on here, but I thought i'd contribute to a bit of a method I came up with today just helping someone else on my OWN forum with saving items as string values in a format to a text style output:

Code:
Dim LVObj As IEnumerable(Of String()) = (From Obj In ListView1.Items.Cast(Of ListViewItem)()
                            Select Obj.SubItems.Cast(Of ListViewItem.ListViewSubItem).Select(Function(i) i.Text).ToArray)
For Each StrArr As String() In LVObj
    Console.WriteLine(String.Join("|", StrArr))
Next

What this does is close to defining an array of arrays, for each row. So LVObj actually contains an array of rows in the ListView as string() values for each column. VERY similar to what is called a jagged array, and in fact, if you defined an extra ToArray in there after selecting the item, it would become a jagged array and do virtually the same thing. In this case I decided to stick with an IEnumerable generic collection however. As it's not needed to get into a jagged array here.

Really nice LINQ going on here though, Looping through each array in the IEnumerable collection of string arrays generated, and outputting them easily with the String.Join method. This could be done with a StreamWriter combination as well to actually write the contents to a file.

The only problem here could be memory if you're pushing the limits of the ListView control itself with tons of data, and in that case I would loop through the items, select my strings at that time, and write all at the same time, not storing anything in memory.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply







Users browsing this thread: 1 Guest(s)