Home General VB/VBA Save/Load Listview data to/from Textfile
20 | 05 | 2012
This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade

Save/Load Listview data to/from Textfile PDF Print E-mail
User Rating: / 0
PoorBest 
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

Show/Hidden vbnet code

View source
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 Function

Download the complete code to get something like this:

Save listview

Attachments:
FileDescriptionFile sizeDownloads
Download this file (FRMlistviewloadsave.zip)FRMlistviewloadsave.zip 1 Kb1064
 

Comments   

 
0 #1 Guest 2011-12-07 08:53
hi there
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
Quote
 

Add comment


Security code
Refresh

This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade