Results 1 to 5 of 5

Thread: [RESOLVED] ListView Speed Problem

  1. #1

    Thread Starter
    Lively Member matt3011's Avatar
    Join Date
    May 2002
    Location
    France
    Posts
    82

    Resolved [RESOLVED] ListView Speed Problem

    I am adding ListViewItems to a listView from a SQLDataReader. The problem is that when the number of items grows, the time to add them to the listbox grows exponentially.

    For example, when I add 22 items, the SQL Query takes 40ms and the loop to insert data takes 1300ms
    For 125 items, it's 60ms For the SQL Query and 99 895ms for the loop
    For 250 items, it's 1030ms for the SQL Query and 470 000ms for the loop

    I suspend the layout of the listview during insertion and there is no calculation in the loop, only a few conditions.

    What am I missing ? I can't see anything wrong in my code which goes roughly like this :
    VB Code:
    1. Redim strItem(nbColumn-1)
    2. myListView.SuspendLayout
    3. RS=myConnect.executeReader(Query)
    4. Do While RS.Read
    5.     strItem(0) = rs("id")
    6.     strItem(1) = rs("client")
    7.     ...
    8.     item = New ListViewItem(strItem)
    9.     Select Case strItem(x)
    10.               Case SomeCondition
    11.                    item.BackColor = Color.Black
    12.                    item.ForeColor = Color.White
    13.               Case OtherCondition
    14.                    item.BackColor = Color.Red
    15.                    item.ForeColor = Color.Black
    16.               Case Else
    17.                    item.BackColor = Color.White
    18.                    item.ForeColor = Color.Black
    19.     End Select
    20. myListView.Items.Add(item)
    21. Loop
    22. myListView.ResumeLayout

    Any Help would be great. Thanks
    Last edited by matt3011; Jul 4th, 2005 at 11:20 AM.

  2. #2
    Fanatic Member
    Join Date
    May 2005
    Posts
    898

    Re: ListView Speed Problem

    I think you're supposed to use ListView.BeginUpdate and ListView.EndUpdate
    "so just keep in mind that fantasy is not the same as realtiy and make sure u remember that wii sports may be fun but u cant count on it as exercise ok cool bye" - HungarianHuman

  3. #3

    Thread Starter
    Lively Member matt3011's Avatar
    Join Date
    May 2002
    Location
    France
    Posts
    82

    Re: ListView Speed Problem

    It doesn't change anything at all. I assume that the effect of ListView.BeginUpdate is the same as ListView.SuspendLayout. It just doesn't allow the control to redraw unless ListView.EndUpdate Or Listview.ResumeLayout is called

  4. #4
    Hyperactive Member temp_12000's Avatar
    Join Date
    Jan 2004
    Location
    LA, USA
    Posts
    411

    Re: ListView Speed Problem

    Quote Originally Posted by matt3011
    What am I missing ? I can't see anything wrong in my code which goes roughly like this :
    VB Code:
    1. Redim strItem(nbColumn-1)
    2. myListView.SuspendLayout
    3. RS=myConnect.executeReader(Query)
    4. Do While RS.Read
    5.     strItem(0) = rs("id")
    6.     strItem(1) = rs("client")
    7.     ...
    8.     item = New ListViewItem(strItem)
    9.     Select Case strItem(x)
    10.               Case SomeCondition
    11.                    item.BackColor = Color.Black
    12.                    item.ForeColor = Color.White
    13.               Case OtherCondition
    14.                    item.BackColor = Color.Red
    15.                    item.ForeColor = Color.Black
    16.               Case Else
    17.                    item.BackColor = Color.White
    18.                    item.ForeColor = Color.Black
    19.     End Select
    20. myListView.Items.Add(item)
    21. Loop
    22. myListView.ResumeLayout

    Any Help would be great. Thanks

    1) Maybe you can add items first, then change color after u insert all items.
    2) Add item, then add subitem. do not just use 'item = New ListViewItem(strItem)', stritem is an array, it may slow down ur program.

    I used listview in my program, it should not be so slow.



  5. #5

    Thread Starter
    Lively Member matt3011's Avatar
    Join Date
    May 2002
    Location
    France
    Posts
    82

    Re: ListView Speed Problem

    Ok, I pointed the problem out. I have a ListView.ListViewItemSorter set on my control, and it is active when inserting data.
    I now set it to nothing when inserting data and I set it back when finished.

    I have to wait 6s to sort my listview now. Does Anyone know what algorithm MS uses in their Sort() Method, I think it's in n², so maybe it should be interesting if someone had implemented one in n.log(n).

Posting Permissions

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



Click Here to Expand Forum to Full Width