Solved

vb.net - add item to listview

Posted on 2013-01-21
1
504 Views
Last Modified: 2013-01-21
hello,
I have this little code here to load data into a listview from a text file..
how can I change that up so it loads from a string called "strData"
that has the records line by line

            Using sr As New System.IO.StreamReader(strData, True)
                While Not sr.EndOfStream
                    strLine = sr.ReadLine
                    If strLine <> "" And Not strLine.StartsWith("#") Then
                        tabLine = strLine.Split(strSept)
                        lItem = lstView.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 5
                            lItem.SubItems.Add(tabReplace(j))
                        Next j

                        lItem.SubItems(3).Text = "0"
                        lItem.SubItems(4).Text = "0"
                    End If
                End While
            End Using

Open in new window

0
Comment
Question by:XK8ER
1 Comment
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 38803866
Just use Split() on strData with a For loop:
        For Each strLine In strData.Split(vbCrLf.ToCharArray, StringSplitOptions.RemoveEmptyEntries)
            If strLine <> "" And Not strLine.StartsWith("#") Then
                tabLine = strLine.Split(strSept)
                lItem = lstView.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 5
                    lItem.SubItems.Add(tabReplace(j))
                Next j

                lItem.SubItems(3).Text = "0"
                lItem.SubItems(4).Text = "0"
            End If
        Next

Open in new window

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

932 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now