Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

vb.net - add item to listview

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
defining NULL or 0 10 44
Need a simple RegEx to search for two words 27 42
IEnumerable<T> to a List<T> 8 37
C# Linq Select From List 3 10
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

840 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