dcsimg
Results 1 to 10 of 10

Thread: ListView with many SubItems is extremely slow

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2010
    Posts
    112

    ListView with many SubItems is extremely slow

    I am facing a issue that ListView becomes extremely laggy when I add many SubItems. For example, when I try to do a horizontal scroll, it takes about 1 second to update/repaint and that is not acceptable.

    I want to be able to show small amount of rows (<50), but large amount of columns (>400). Only a few columns will be visible at the time. I also need to be able to set individual back colors to separate cells. Data within my list view will be populated once and not from the database.

    I have tried enabling a double buffering and using a virtual mode, but it did not help much, if at all. I have found some 3rd party ListView alternatives, but they either did not work or had many unnecessary features and hence were very expensive to purchase.

    Can you suggest how to fix this issue? Here is my sample code:

    Code:
    Private ListView1 As New ListView With {.Size = New Size(300, 400)}
    
    Private Sub Form1_Load() Handles Me.Load
    	Const columns = 500
    	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()
    		'.DoubleBuffered(True)
    	End With
    End Sub

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    22,355

    Re: ListView with many SubItems is extremely slow

    To use differing colours set EnableVisualStyles.
    I'm not sure about how to speed the scrolling up...

  3. #3
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,153

    Re: ListView with many SubItems is extremely slow

    A DataGridView might be faster, worth a try.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    22,355

    Re: ListView with many SubItems is extremely slow

    400 columns is quite substantial, but a DGV probably would be faster, and they have a lot you can modify to get a similar look to a ListView

  5. #5
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,153

    Re: ListView with many SubItems is extremely slow

    To be honest, I don't think having 400 columns in a ListView or DataGridView is a good idea. That just seems like to much to make the user search through. If possible I'd filter the columns to suit the user needs.

  6. #6
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,542

    Re: ListView with many SubItems is extremely slow

    but large amount of columns (>400). Only a few columns will be visible at the time.
    This is your problem you thinking about this in the wrong way, if only a few columns will be visible at any time, then only load the data with those columns, when you need different data load it with a different set of columns.

    Loading them all and hiding them or showing them based upon conditions is not a good idea and wont be much less code really then just having different methods loading the list view for the different views you want.

    400 columns is ALOT of columns and is almost certainly causing your scrolling speed issues!
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2010
    Posts
    112

    Re: ListView with many SubItems is extremely slow

    Quote Originally Posted by wes4dbt View Post
    To be honest, I don't think having 400 columns in a ListView or DataGridView is a good idea. That just seems like to much to make the user search through.
    You do not know what I am trying to use it for. To put is simply, it will be used to visually recognize patterns in data sets. I see absolutely nothing wrong with having many columns in this case.

    Quote Originally Posted by NeedSomeAnswers View Post
    400 columns is ALOT of columns and is almost certainly causing your scrolling speed issues!
    In this day and age 400 columns is ridiculously small number given the processing power an average computer has. I would rather say that we can blame a poorly designed control, if no matter how configured, it cannot dynamically load data from large data sets. Even if I choose not to use a dynamic loading, there is still no reason why ListView should become laggy during the scrolling. All it has to do is to read the data of let say 100 cells and draw those cells. This whole routine is in no way a CPU intensive task.

    I have just tried a 3rd party alternative control. It can literally load million data entries and shows no lag at all. I guess I will have to stick with it, given that ListView is not capable of accomplishing this task.

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    22,355

    Re: ListView with many SubItems is extremely slow

    Quote Originally Posted by riov View Post
    You do not know what I am trying to use it for. To put is simply, it will be used to visually recognize patterns in data sets. I see absolutely nothing wrong with having many columns in this case.


    In this day and age 400 columns is ridiculously small number given the processing power an average computer has. I would rather say that we can blame a poorly designed control, if no matter how configured, it cannot dynamically load data from large data sets. Even if I choose not to use a dynamic loading, there is still no reason why ListView should become laggy during the scrolling. All it has to do is to read the data of let say 100 cells and draw those cells. This whole routine is in no way a CPU intensive task.

    I have just tried a 3rd party alternative control. It can literally load million data entries and shows no lag at all. I guess I will have to stick with it, given that ListView is not capable of accomplishing this task.
    A ListView is a display control. If you're doing serious data crunching, I'd recommend either using a DataGridView, or doing all of your calculations with arrays in memory...

  9. #9
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,968

    Re: ListView with many SubItems is extremely slow

    Hi,

    I think you will have to implement some kind of 'Pageing' method -< show 15 columns then with Button or Key Right/Left
    move forward or back to the next/previous 15 Columns

    also the Listview has a AddRange method rather than just .Items.Add
    Last edited by ChrisE; Jul 20th, 2019 at 12:11 AM.
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,381

    Re: ListView with many SubItems is extremely slow

    The ListView is a GRAPHICAL display control... not a data display control. By your logic, I should be able to take a VW Bug to an F1 race, then simply claim that it's due to the poor design of the car that I didn't win the race. No...that's not it at all... the ListView has a purpose, and displaying gobs of data all at once isn't it... It can handle the data, just not all at once... you have to paginate it some how... either by virtual views and only load the data as it comes into view, or by adding buttons to navigate the pages.

    If some other control can handle it, my guess is that it was built from scratch to handle data from the get go and isn't a graphical control, but a data control.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width