Link to home
Start Free TrialLog in
Avatar of XK8ER
XK8ERFlag for United States of America

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: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

Avatar of jtdebeer
jtdebeer

Try the Replace keyword
Replace(StrName,"Phone","1800-123-1234")
Avatar of Mike Tomlinson
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 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
Avatar of XK8ER

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?
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial