Solved

Populate list vist from text with visual basic .net

Posted on 2013-01-29
2
234 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
[X]
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
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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 …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

737 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