|
-
Jul 4th, 2005, 11:08 AM
#1
Thread Starter
Lively Member
[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:
Redim strItem(nbColumn-1)
myListView.SuspendLayout
RS=myConnect.executeReader(Query)
Do While RS.Read
strItem(0) = rs("id")
strItem(1) = rs("client")
...
item = New ListViewItem(strItem)
Select Case strItem(x)
Case SomeCondition
item.BackColor = Color.Black
item.ForeColor = Color.White
Case OtherCondition
item.BackColor = Color.Red
item.ForeColor = Color.Black
Case Else
item.BackColor = Color.White
item.ForeColor = Color.Black
End Select
myListView.Items.Add(item)
Loop
myListView.ResumeLayout
Any Help would be great. Thanks
Last edited by matt3011; Jul 4th, 2005 at 11:20 AM.
-
Jul 4th, 2005, 11:11 AM
#2
Fanatic Member
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
-
Jul 4th, 2005, 11:19 AM
#3
Thread Starter
Lively Member
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
-
Jul 4th, 2005, 03:26 PM
#4
Hyperactive Member
Re: ListView Speed Problem
 Originally Posted by matt3011
What am I missing ? I can't see anything wrong in my code which goes roughly like this :
VB Code:
Redim strItem(nbColumn-1)
myListView.SuspendLayout
RS=myConnect.executeReader(Query)
Do While RS.Read
strItem(0) = rs("id")
strItem(1) = rs("client")
...
item = New ListViewItem(strItem)
Select Case strItem(x)
Case SomeCondition
item.BackColor = Color.Black
item.ForeColor = Color.White
Case OtherCondition
item.BackColor = Color.Red
item.ForeColor = Color.Black
Case Else
item.BackColor = Color.White
item.ForeColor = Color.Black
End Select
myListView.Items.Add(item)
Loop
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.
-
Jul 5th, 2005, 04:02 AM
#5
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|