question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ListView slow and max width

See original GitHub issue

ListView becomes slow when it contains many columns, even if only a few of them are displayed. Here is a sample code that illustrates the issue. When you try to scroll it, it takes a long time to repaint. Virtual mode does not help. I am not really sure why it takes so long to paint 120 cells.

Private ListView1 As New ListView With {.Size = New Size(300, 400)}

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
    Const columns = 600
    Controls.Add(ListView1)

    With ListView1
        .BeginUpdate()
        .View = View.Details
        .HeaderStyle = ColumnHeaderStyle.Nonclickable

        For c = 1 To columns
            .Columns.Add(c.ToString, 50, HorizontalAlignment.Center)
        Next

        For r = 1 To 20
            Dim l As New ListViewItem(r & "1")
            For c = 2 To columns
                l.SubItems.Add(r & c)
            Next
            .Items.Add(l)
        Next
        .EndUpdate()
    End With
End Sub

Another issue I found is that it looks like there is a limitation of how large the width of all columns can be, i. e. in my sample code you can change the column count to 700 and observe how the last columns will not be visible. The last ones that will be visible will not allow you to change their width.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
r-aghaeicommented, Aug 12, 2019

@riov For the columns rendering, the behavior is the same in .NET Framework. For the scroll/repaint I couldn’t see any problem. For the resize issue, I believe it’s a limitation in the Windows message. Consider WM_MOUSEMOVE, the lParam parameter determines the mouse position. The low-order word specifies the x-coordinate and the high-order word specifies the y-coordinate of the cursor. Using 16 bit for x and 16 bit for y means it can not handle coordinates larger that 32767. That’s why if you create a lot of columns, for the right most columns (which their x-coordinate is larger that 32767) you cannot change the column size, the column even do not get highlighted by mouse. If you take a look at WM_MOUSEMOVE message using spy++, you will see negative x-coordinate for them.

0reactions
RussKiecommented, Aug 13, 2019

Anyway, I would like to suggest two new features:

Could you please raise separate issues for each one, thank you. Because both of these suggestions affect public API we’ll need to have an assessment how these changes will affect existing consumers.

It remains a mystery to me, why ListsView cannot show the same performance.

Not sure, it could be an underlying limitation of Win32 API… A Windows Explorer struggles to scroll when one has beyond certain number of files in a folder too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WPF ListView very poor performance with large data
The problem entirely disappears as soon as I set the MaxHeight of the ListView to something bigger than it needs.
Read more >
ListView and GridView UI optimization - UWP applications
Improve ListView and GridView performance and startup time through UI virtualization, element reduction, and progressive updating of items.
Read more >
Optimizing Listview performance
Hello, I'm currently working on a project (which I inherited) where I'm using a listview to display setting screens.
Read more >
Adding Items is slow with ListView - AutoHotkey Community
I'm expecting up to a few thousand items (MAX) being populated, and the speed is going to be a limiting factor for end...
Read more >
Slow rendering of GridView with 60 elements x 3 checkboxes
I'm investigating why / how to improve the rendering speed of a rather complex UserControl / Window The Window contains a Tab-Control where ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found