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:phone
firstname2:lastname2:email:address:phone
firstname3:lastname3:email:address:phone

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

Open in new window

LVL 1
XK8ERAsked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
You could pop it it in at the bottom of your "If" block:

                    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

                        lItem.SubItems(4).Text = "1800-123-1234"
                    End If
0
 
jtdebeerCommented:
Try the Replace keyword
Replace(StrName,"Phone","1800-123-1234")
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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"
0
 
planoczCommented:
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(tabReplace(j)) )
               Next j
0
 
XK8ERAuthor Commented:
>>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?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.