XK8ER
asked on
vb.net - load data into listview
hello there,
I am using this code bellow and its working perfectly fine to load data from a text file into my listview. if the text file has data like this
firstname1:lastname1
firstname2:lastname2
firstname3:lastname3
it will load it up on the listview like this
firstname1:lastname1:email :address:p hone
firstname2:lastname2:email :address:p hone
firstname3:lastname3:email :address:p hone
and if the text file doesnt have any missing columns then it will load them correctly.. so my questions will be how can I make the code replace phone with this "1800-123-1234" always
I am using this code bellow and its working perfectly fine to load data from a text file into my listview. if the text file has data like this
firstname1:lastname1
firstname2:lastname2
firstname3:lastname3
it will load it up on the listview like this
firstname1:lastname1:email
firstname2:lastname2:email
firstname3:lastname3:email
and if the text file doesnt have any missing columns then it will load them correctly.. so my questions will be how can I make the code replace phone with this "1800-123-1234" always
Public Sub LoadUserInfo(ByVal mPath As String, ByVal LVW As ListView)
If System.IO.File.Exists(mPath) Then
Dim strLine As String, tabLine() As String, lItem As ListViewItem, tabReplace() As String = {"", "", "email", "address", "phone"}
Using sr As New System.IO.StreamReader(mPath)
While Not sr.EndOfStream
strLine = sr.ReadLine
If strLine <> "" Then
tabLine = strLine.Split(":")
lItem = LVW.Items.Add(tabLine(0))
For j As Integer = 1 To tabLine.GetUpperBound(0)
lItem.SubItems.Add(tabLine(j))
Next j
For j As Integer = tabLine.Count To 4
lItem.SubItems.Add(tabReplace(j))
Next j
End If
End While
End Using
End If
End Sub
Are you asking how to make any EMPTY phone fields always be "1800-123-1234"?
You could just replace "phone" with your value, as jtdebeer alludes to:
tabReplace() As String = {"", "", "email", "address", "1800-123-1234"}
If you want to make ALL fields have that value, regardless of whether they had a value in the file or not, then:
lItem.SubItems(4).Text = "1800-123-1234"
You could just replace "phone" with your value, as jtdebeer alludes to:
tabReplace() As String = {"", "", "email", "address", "1800-123-1234"}
If you want to make ALL fields have that value, regardless of whether they had a value in the file or not, then:
lItem.SubItems(4).Text = "1800-123-1234"
You might try this .....
If you just need to have a empty column field in the Listview
For j As Integer = tabLine.Count To 4
IIF(tabReplace(j) = "" , " " , lItem.SubItems.Add(tabRepl ace(j)) )
Next j
If you just need to have a empty column field in the Listview
For j As Integer = tabLine.Count To 4
IIF(tabReplace(j) = "" , " " , lItem.SubItems.Add(tabRepl
Next j
ASKER
>>If you want to make ALL fields have that value, regardless of whether they had a value in the file or not, then: lItem.SubItems(4).Text = "1800-123-1234"
where do I place that line?
where do I place that line?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Replace(StrName,"Phone","1