Solved

Populate list vist from text with visual basic .net

Posted on 2013-01-29
2
218 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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)…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

17 Experts available now in Live!

Get 1:1 Help Now