?
Solved

vb.net - load data into listview

Posted on 2009-12-28
5
Medium Priority
?
517 Views
Last Modified: 2012-05-08
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

0
Comment
Question by:XK8ER
5 Comments
 
LVL 8

Expert Comment

by:jtdebeer
ID: 26131060
Try the Replace keyword
Replace(StrName,"Phone","1800-123-1234")
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 26131860
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
 
LVL 27

Expert Comment

by:planocz
ID: 26133027
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
 
LVL 1

Author Comment

by:XK8ER
ID: 26134747
>>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
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 200 total points
ID: 26134843
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question