borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (I have time but its all wrong)Next Topic (opening excel in VB) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Big Problem... Need it Solved!
Poster Message
NeedHelpPlz
Level: Guest


icon Big Problem... Need it Solved!  Archived to Disk

My program saves data to a text file, about 45 lines to it. Each line has data that is loaded upon the file being opened.

Now, I am stuck. I need to save a ListView's Report Mode data after the previous data, and load it into the program later.

There are 4 columns in the ListView control, and I need to be able to save each row of data, and load it later.

HOW CAN I DO THIS!? I have tried everything I can think of, but nothing works!

Thanks!

03-06-2002 at 04:24 PM
| Quote Reply
GPA
Level: Guest

icon Re: Big Problem... Need it Solved!  Archived to Disk

Perhaps you can save current data into an array and load it into your listview later.

For a better answer, ask better questions.
Guus

11-06-2002 at 07:56 AM
| Quote Reply
NeedHelpPlz
Level: Guest

icon Re: ListView Problem  Archived to Disk

GPA, how does saving a ListView to an array work, and how do I implement it?

Thanks

13-06-2002 at 10:54 PM
| Quote Reply
JDP
Level: Guest

icon 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
| Quote Reply
AndreaVB Forum : VB General : Big Problem... Need it Solved!
Previous Topic (I have time but its all wrong)Next Topic (opening excel in VB) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder