Solved

Populate list vist from text with visual basic .net

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 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

24 Experts available now in Live!

Get 1:1 Help Now