Solved

Populate list vist from text with visual basic .net

Posted on 2013-01-29
2
230 Views
Last Modified: 2013-01-29
I have some output from Linux server that I would like to display in a list view.  I would like to remove the first 2 rows and show the rest.  Depending on the search , the number of rows can change.  Here is what the output looks like:


 Job Name Last Start Last End ST Run Pri/Xit
 ____________________________ ____________________ ____________________ __ _______ ___
 CLONB001 01/29/2013 07:30:18 01/29/2013 07:33:41 SU 1014638/1
 CLONS001 01/29/2013 07:30:19 01/29/2013 07:31:59 SU 1014638/1
 CLONS002 01/29/2013 07:32:01 01/29/2013 07:33:41 SU 1014638/1


How can I change my string to populate a list view, but remove the first 2 rows?
0
Comment
Question by:chadmanvb
2 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 38831479
Dim lines As var = File.ReadAllLines(filePath).Skip(2)
For Each line As var In lines
    listView1.Items.Add(New ListViewItem(line.Split(' ')))
Next

Open in new window


that will get you all the lines besides the first 2, and populate your listview
0
 

Author Closing Comment

by:chadmanvb
ID: 38831925
Thanks!  I had to make some changes because of the way time could be displayed.  Here is what I ended up with

 'parse results and fill listview
        Dim intCount As Integer = 0
        ListView1.Items.Clear()
        Dim item1 As ListViewItem
        For Each line In strResults
            intCount += 1
            If intCount = 1 Or intCount = 2 Then
                'skip first 2 lines
            Else

                Dim strSplit() As String = line.Trim.Split(" ")
                item1 = New ListViewItem
                item1.Text = strSplit(0).ToString
                'figure out if a time is listed
                If strSplit(1).Trim = "-----" And strSplit(2) = "-----" Then
                    'MsgBox(line & "    *********NO TIME")
                    item1.SubItems.Add("NA")    'start time
                    item1.SubItems.Add("NA")    'end time
                    item1.SubItems.Add(GetStatus(strSplit(3)))  'status


                ElseIf strSplit(1).Trim = "-----" And strSplit(2) <> "-----" Then
                    'MsgBox(line & "    *********STOP")
                    item1.SubItems.Add("NA")    'start time
                    item1.SubItems.Add(strSplit(2) & " " & (strSplit(3)).ToString())  'end time
                    item1.SubItems.Add(GetStatus(strSplit(4)))  'status

                ElseIf strSplit(1).Trim <> "-----" And strSplit(3) = "-----" Then
                    'MsgBox(line & "    *********START")
                    item1.SubItems.Add(strSplit(1) & " " & (strSplit(2)).ToString())  'end time
                    item1.SubItems.Add("NA")    'start time
                    item1.SubItems.Add(GetStatus(strSplit(4)))  'status

                Else
                    'this is will show both start and stop time
                    'MsgBox(line & "    *********BOTH")
                    item1.SubItems.Add(strSplit(1) & " " & (strSplit(2)).ToString())  'end time
                    item1.SubItems.Add(strSplit(3) & " " & (strSplit(4)).ToString())  'start time
                    item1.SubItems.Add(GetStatus(strSplit(5)))  'status

                End If


                ListView1.Items.Add(item1)


            End If



        Next
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

685 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