Optimization of Listbox Population

I'm having some trouble creating an optimized function to split strings within a text file, and populate my ListView accordingly. For the function below, it's taking 32 seconds to get through 40,000 lines.

The only goal is to take each line of a text file, delimited by a space, and input them into the corresponding column. Any suggestions on a faster way to sort through these lines? I did also try Regulator Expression for splitting, but that did not help.

This blog had some great benchmarking for what I'm trying to accomplish, but I'm having trouble adapting it to my function: http://cc.davelozinski.com/c-sharp/fastest-way-to-read-text-files

    Dim ColDate As String
    Dim Time As String
    Dim Action As String
    Dim Protocol As String
    Dim Source As String
    Dim Destination As String
    Dim SourcePort As String
    Dim DestPort As String

    Dim logFileStream As FileStream = New FileStream(My.Settings.LogLocation, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
    Dim reader As StreamReader = New StreamReader(logFileStream)
    Dim line As String

    Do
        line = reader.ReadLine
        Try
                'Make sure it's not a comment
                If line.StartsWith("#") Then
                    Exit Try
                End If

                Dim split As String() = line.Split(" ")
                ColDate = split(0)
                Time = split(1)
                Action = split(2)
                Protocol = split(3)
                Source = split(4)
                Destination = split(5)
                SourcePort = split(6)
                DestPort = split(7)

                frmMain.lstLogs.Items.Add(ColDate)
                frmMain.lstLogs.Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(Time)
                frmMain.lstLogs.Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(Action)
                frmMain.lstLogs.Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(Protocol)
                frmMain.lstLogs.Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(Source)
                frmMain.lstLogs.Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(Destination)
                frmMain.lstLogs.Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(SourcePort)
                frmMain.lstLogs.Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(DestPort)

            Catch ex As Exception
                'MsgBox(ex.ToString)
            End Try
        'End If
    Loop Until reader.EndOfStream
    reader.Close()

Don't update a User Interface inside a loop without .BeginUpdate and .EndUpdate. I was working with a ListView with approximately 1500 rows and they appear instantaneously.

I created a list of ListViewItem s. Then looped through my data adding the details of each new ListViewItem and adding it to the list. After the loop a .ToArray allowed me to use the .AddRange method of the ListView. This is surrounded by begin and end update. No screen redraws speeds things up a great deal.

Private Sub OpCode()
    Dim lstListItems As New List(Of ListViewItem)
    Dim lines = File.ReadAllLines(My.Settings.LogLocation) 'Assume this is the path to the file you are reading
    For Each line In lines
        'Make sure it's not a comment
        If line.StartsWith("#") Then
            Continue For
        End If

        Dim split As String() = line.Split(" "c)

        Dim li As New ListViewItem
        li.Text = split(0) 'ColDate
        li.SubItems.Add(split(1)) 'Time
        li.SubItems.Add(split(2)) 'Action
        li.SubItems.Add(split(3)) 'Protocol
        li.SubItems.Add(split(4)) 'Source
        li.SubItems.Add(split(5)) 'Destination
        li.SubItems.Add(split(6)) 'SourcePort
        li.SubItems.Add(split(7)) 'DestPort

        lstListItems.Add(li)
    Next
    'Assume that lstLogs is the name of your ListView control
    lstLogs.BeginEdit
    lstLogs.Items.AddRange(lstListItems.ToArray)
    lstLogs.EndEdit
End Sub

WPF and Silverlight Super-Productivity: ListBoxes, Figure 4: A read-optimized version of our ListBox makes it easier to absorb the most Some people would call this the chrome, which is all the window dressing​  I want to create a ListBox which is filtered by the selection of the 3rd ComboBox. Below the Access table design and below that the code I have so far. The form also contains a clear fields button which clears the comboboxes at the moment but also needs to clear the ListBox. The DB has the following tables and columns: Category. CategoryID

Instead of using a StreamReader , I think you should read the text file then loop over the lines. Try this ::

Dim ColDate As String
Dim Time As String
Dim Action As String
Dim Protocol As String
Dim Source As String
Dim Destination As String
Dim SourcePort As String
Dim DestPort As String

Dim logFile As String() = IO.File.ReadAllLines(My.Settings.LogLocation)
For Each line in logFile
    Try
        'Make sure it's not a comment
        If line.StartsWith("#") Then
            Exit Try
        End If

        Dim split As String() = line.Split(" ")
        ColDate = split(0)
        Time = split(1)
        Action = split(2)
        Protocol = split(3)
        Source = split(4)
        Destination = split(5)
        SourcePort = split(6)
        DestPort = split(7)

        frmMain.lstLogs.Items.Add(ColDate)
        frmMain.lstLogs.Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(Time)
        frmMain.lstLogs.Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(Action)
        frmMain.lstLogs.Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(Protocol)
        frmMain.lstLogs.Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(Source)
        frmMain.lstLogs.Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(Destination)
        frmMain.lstLogs.Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(SourcePort)
        frmMain.lstLogs.Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(DestPort)

    Catch ex As Exception
        'MsgBox(ex.ToString)
    End Try
Next

XAML Anti-Patterns: Virtualization, Imagine a ListBox in a WPF application (or any of the other XAML The system can even fall behind as people try to scroll up and down, and the problem I did some old-fashioned optimization and managed to get the load time from more  Population Pharmacokinetics and Dosing Optimization of Linezolid in Pediatric Patients. Li SC(1), Ye Q(1), Xu H(1), Zhang L(2), Wang Y(3). Author information: (1)Department of Clinical Pharmacy, Wuhan Children's Hospital, Tongji Medical College, Huazhong University of Science & Technology, Wuhan, China.

Exclude array from code

Dim split As String() = line.Split(" ")

Replace lines of code

With line
    ColDate = .Split(" ")(0)
    Time = .Split(" ")(1)
    Action = .Split(" ")(2)
    Protocol = .Split(" ")(3)
    Source = .Split(" ")(4)
    Destination = .Split(" ")(5)
    SourcePort = .Split(" ")(6)
    DestPort = .Split(" ")(7)
End Wiht

With frmMain.lstLogs
  .Items.Add(ColDate)
  .Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(Time)
  .Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(Action)
  .Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(Protocol)
  .Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(Source)
  .Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(Destination)
  .Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(SourcePort)
  .Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(DestPort)
 End Wiht

OR

With frmMain.lstLogs
  .Items.Add(line.Split(" ")(0))
  .Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(line.Split(" ")(1))
  .Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(line.Split(" ")(2))
  .Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(line.Split(" ")(3))
  .Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(line.Split(" ")(4))
  .Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(line.Split(" ")(5))
  .Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(line.Split(" ")(6))
  .Items(frmMain.lstLogs.Items.Count - 1).SubItems.Add(line.Split(" ")(7))
 End Wiht

Listbox population using two codes supplied, My job is to use the last code for populating the listbox as opposed to Listbox population using two codes supplied. Thread starter ipbr21054 Code optimization required - run all processes in memory before placing result to worksheet. <zk> <listbox mold="select" rows="1"> <listitem label="Car"/> <listitem label="Taxi"/> <listitem label="Bus" selected="true"/> <listitem label="Train"/> </listbox> </zk> Scrollable Listboxes A list box will be scrollable if it has a defined or automatically calculated height (e.g. by specifying the rows , height or vflex attribute) and there is

List Box · 4D Documentation, the list box object in its entirety,; columns,; column headers, and; column footers. If you click on the "Population" header to sort the populations by ascending (or You can optimize hierarchical list boxes display and management using the  Here is the VBA list box default values in Excel. After adding items to list box by using any of the below code you can define the default value. Code 1: The below code is useful to select blank option in list box. Where ‘-1’ is the index number. Sub LstBx_Dflt_Val_Ex1() UserForm3.ListBox1.ListIndex = -1 End Sub Code 2:

Optimizing GtkListBox for many rows, Re: Optimizing GtkListBox for many rows I've talked to at least 4 people about this and I know a few others have worked on an  An optimization to UI virtualization added in the .NET Framework 3.5 SP1 for controls that inherit from ItemsControl is container recycling, which can also improve scrolling performance. When an ItemsControl that uses UI virtualization is populated, it creates an item container for each item that scrolls into view and destroys the item

Why did this error message appear? - MATLAB Answers, Warning: single-selection list box control requires that Value be an integer within String I am using a software which is MATLAB based for optimization. If it is important start a new question and give plenty of details to help people help you. Population pharmacokinetic modeling demonstrated that teicoplanin pharmacokinetics were well described by a two compartment model with first order elimination. Our results are consistent with the findings of previous population pharmacokinetic studies conducted in adults 19–21. All these three studies in adults have shown that the population

Comments
  • This completed 43,000 records in 5.548 seconds. Thank you! I really appreciate your guidance Mary!
  • I noticed lstLogs.Items.AddRange(lstListItems.ToArray) seems to also cause a UI hang. I added your suggested code into a Background Worker because I thought it would solve the hang, but the hang is a result of rendering the UI listview element I believe. And then of course you're not allowed to access the UI from a thread, so I'm a bit lost there.
  • Well, that is a great deal of rows to put in a UI. I am not sure how a user could scroll through all of that, Possibly you could could make lstListItems a Class level variable and only load part of the items from the list. You did add the .BeginEdit and .EndEdit, yes?
  • Yes that's correct. I think you're right, it's an inevitable hangup. Perhaps I'll change the function to add the items in pairs of ~100. Or try my hand at using a database instead of a LV. Thank you Mary =)