Solved

vb.net - add item to listview

Posted on 2013-01-21
1
503 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

705 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

20 Experts available now in Live!

Get 1:1 Help Now