 |
|
 |
JDP Level: Guest

|
Re: Re: ListView Problem Archived to Disk
quote: NeedHelpPlz wrote:
GPA, how does saving a ListView to an array work, and how do I implement it?
Thanks
I know this is an old post but I came upon it while searching for the answer to the same question myself. I never did find the answer on any forum, (and I trawled through a lot of them!) so had to buckle down and work it out myself
So, just in case anyone else follows me later in search of the same help, here's what I came up with. It's not very elegant, but
(a) it works and
(b) it's a lot more help than GPA's answer was !
First, the code for writing to a text file:
(The listview is named LV1. )
Open DataFile For Output As #FileNumber
' Grab the Main (First Col) Item and save it as Temp
For i = 1 To LV1.ListItems.Count
Temp = LV1.ListItems.Item(i)
' Grab the SubItems for this main item:
For j = 1 To (LV1.ListItems(i).ListSubItems.Count)
' Store it temporarily in the SubItems() array
SubItems(j) = LV1.ListItems(i).ListSubItems(j)
Next
' Write the main item on its own line to the file.
Write #FileNumber, Temp
' Write all the subitems on the next line
Write #FileNumber, SubItems(1), SubItems(2), SubItems(3), SubItems(4), SubItems(5)
' Clear the array in case the next Row has less subitems in it
' (Reason being that it will "remember" previous entries and cause incorrect duplications)
For y = 0 To 10
SubItems(y) = " "
Next
Next
Close #FileNumber
|
Then, to read it back and display it in LV1:
FileNumber = FreeFile
Dim OtherCols As String
Dim ColOne As String
Dim Count As Integer
LV1.ListItems.Clear
Open DataFile For Input As #FileNumber
' Set LV Row Counter to 1
Count = 1
Do While Not EOF(FileNumber) ' Loop until end of file.
' First, get the Column 1 Main Item
Input #FileNumber, ColOne
LV1.ListItems.Add , , ColOne ' Show it in the LV
Line Input #FileNumber, OtherCols
' Now split othercols using comma as delimiter
Dim SplitMe() As String
Dim z As Integer
SplitMe = Split(OtherCols, "," )
For z = LBound(SplitMe) To UBound(SplitMe)
' Trim off the Quotes from the TextFile
SplitMe(z) = Right$(SplitMe(z), Len(SplitMe(z)) - 1)
SplitMe(z) = Left$(SplitMe(z), Len(SplitMe(z)) - 1)
' Add this SubItem to the current row in the LV
LV1.ListItems.Item(Count).ListSubItems.Add , , SplitMe(z)
Next z
Count = Count + 1 ' Increment LV Row Counter
Loop
Close #FileNumber ' Close file.
|
As I say, it's clunky, but it works.
Hope this helps someone else in the future!
Jack D
|
|
05-08-2002 at 09:36 PM |
|
|  |
|
|
|
|
 |
 |