textfile to streamreader to listview
k..i got a listview i need to load a text file into it.....
text file looks like this...
Username1
Password1
Username2
Password2
i got my save to file sub lookin like this...
Code:
Private Sub SaveList()
Dim sTemp As String = Application.StartupPath.ToString & "\idlist.txt"
Dim sTemp1 As String
' Loop through and save all items in list.
If (LV_IDList.Items.Count > 0) Then
Try
Dim i As Integer
' Create a StreamWriter object to write to the file.
Dim writer As New IO.StreamWriter(sTemp, False)
' Write the information to the file one line at a time.
i = 0
Do
If i < LV_IDList.Items.Count Then
sTemp1 = LV_IDList.Items(i).Text & vbNewLine & LV_IDList.Items(i).SubItems(1).Text
writer.WriteLine(sTemp1)
i = i + 1
Else
Exit Do
End If
Loop
' Close the StreamWriter object.
writer.Close()
Catch
End Try
End If
End Sub
now i need to know how to read the file line by line....then i want to add the usernames as an item with the password as the first subitem....
thx in advance
AcE
Re: textfile to streamreader to listview
Sorry for barging in on your thread but iam using the code, thankyou very much.
I have this code working
Code:
Dim strLine, strLine2 As String
Dim strFileName As String = Application.StartupPath & "\Emailed.txt"
' Open the file to read.
Try
sr = IO.File.OpenText(strFileName)
Try
While sr.Peek <> -1
strLine = sr.ReadLine
strLine2 = sr.ReadLine
lsvEmailed.Items.Add(strLine).SubItems.Add(strLine2)
but if i try to add a second subitem like this
Code:
Dim strLine, strLine2, strLine3 As String
Dim strFileName As String = Application.StartupPath & "\Emailed.txt"
' Open the file to read.
Try
sr = IO.File.OpenText(strFileName)
Try
While sr.Peek <> -1
strLine = sr.ReadLine
strLine2 = sr.ReadLine
strLine3 = sr.ReadLine
lsvEmailed.Items.Add(strLine).SubItems.Add(strLine2).SubItems.Add(strLine3)
i get this error
Error 2 'SubItems' is not a member of 'System.Windows.Forms.ListViewItem.ListViewSubItem'.
Can i only add 1 subitem this way?
regards
toe
Re: textfile to streamreader to listview
This is the textfile data format
***name and address erased***
http://img136.imageshack.us/img136/8643/image2dr2.jpg
Iam trying to fill a 3 column listview control
Column 1 = Company Name
Column 2 = date
Column 3 = email addess
Why is "SubItems" not a memeber now while it is when only adding 1 SubItems?
ps
this is also attached to this thread
http://www.vbforums.com/newthread.php
Re: textfile to streamreader to listview
u cant add subitems like that....that would be like adding a subitem to that subitem you just added....;) ....you got to do it like this....
Quote:
can also add them like this
Dim NewItem As Integer NewItem = LV_IDList.Items.Add("NEWITEM1").Index
LV_IDList.Items(NewItem).SubItems.Add("NEWSUBITEM1")
LV_IDList.Items(NewItem).SubItems.Add("NEWSUBITEM2")
LV_IDList.Items(NewItem).SubItems.Add("NEWSUBITEM3")
AcE
Re: textfile to streamreader to listview