What's new

Closed Help me with my project po.

Status
Not open for further replies.

Made-In-Heaven

Honorary Poster
Joined
Nov 10, 2016
Posts
333
Reaction
100
Points
145
Hi, May question lang po ako. Paano po ba masave sa text file ang mga information na nasa listview?

Example:
Ang nasa Listview ay:
Code:
Items                 Price
Coke                  $5
Pepsi                 $3

Paano po ba mautomatically save sa text file pag click ng button? Pa help naman po :(
 
Dim sfile As New SaveFileDialog
With sfile
.Title = "Choose your path to save the information"
.InitialDirectory = "C:\"
.Filter = ( "ONLY Text Files (*.txt) | *.txt" )
End With
If sfile.ShowDialog() = Windows.Forms.DialogResult.OK
Then
Dim Write As New IO.StreamWriter(sfile.FileName)
Dim k As ListView.ColumnHeaderCollection
= lstOutput.Columns
For Each x As ListViewItem
In lstOutput.Items
Dim StrLn As String = ""
For i = 0 To x.SubItems.Count - 1
StrLn += k(i).Text + " :"
+ x.SubItems(i).Text + Space( 3 )
Next
Write.WriteLine(StrLn)
Next
Write.Close() 'Or Write.Flush()
End If


(From Stackoverflow)
 
Private testfile As String = Application.StartupPath & "\testfile.txt"

load data from text file
--------------------------------
ListView1.Items.Clear()
Dim myCoolFileLines() As String = IO.File.ReadAllLines(testfile)
For Each line As String In myCoolFileLines
Dim lineArray() As String = line.Split("#")
Dim newItem As New ListViewItem(lineArray(0))
newItem.SubItems.Add(lineArray(1))
newItem.SubItems.Add(lineArray(2))
ListView1.Items.Add(newItem)
Next


save
--------------------------------
Dim myWriter As New IO.StreamWriter(testfile)
For Each myItem As ListViewItem In ListView1.Items
myWriter.WriteLine(myItem.Text & "#" & myItem.SubItems(1).Text & "#" & myItem.SubItems(2).Text)
Next
myWriter.Close()

Source:
 
Status
Not open for further replies.

Similar threads

Back
Top