| Save/Load Listview data to/from Textfile |
|
|
|
| Tutorials | |
| Written by Administrator | |
|
Below are two function. One to save data from a listview to a textfile. The others loads the textfile back into the listview Public Function SaveLW(Lw As ListView, Fname As String)
***************************************
'**** Code from VisibleVisual.com ******
'***************************************
'This function saves the values from a listbox to a textfile
Dim FileId As Integer
Dim X As Integer
Dim sIdx As Integer
sIdx = Lw.ColumnHeaders.Count - 1
FileId = FreeFile
On Error Resume Next
Open Fname For Output As #FileId
For i = 1 To Lw.ListItems.Count
Write #FileId, Lw.ListItems.Item(i).Text
For X = 1 To sIdx
Write #FileId, Lw.ListItems.Item(i).SubItems(X)
Next
Next
Close #FileId
End Function
Public Function LoadLW(Lw As ListView, Fname As String)
'This function reads the values from a textfile to a textfile
Dim FileId As Integer
Dim LVI As ListItem
Dim fData As New Collection
Dim Buffer As String
Dim X As Integer
Dim i As Integer
Dim sIdx As Integer
sIdx = Lw.ColumnHeaders.Count - 1
i = 0
FileId = FreeFile
On Error Resume Next
Open Fname For Input As #FileId
While Not EOF(FileId)
i = i + 1
For X = 0 To sIdx
Input #FileId, Buffer
fData.Add Buffer
Next
Set LVI = Lw.ListItems.Add
LVI.Text = fData.Item(fData.Count - sIdx)
For Y = 1 To sIdx
LVI.SubItems(Y) = fData.Item(fData.Count + Y - sIdx)
Next
Wend
Close #FileId
End FunctionDownload the complete code to get something like this:
|





Comments
could you make another tutorial with more coluns and items i want to make a program to save more coluns and items
if possible use picture
can you send to my email the project made in VB net 2008
thanks
RSS feed for comments to this post