|
-
Jan 8th, 2003, 04:05 PM
#1
Thread Starter
New Member
Listview ....very SLOW when adding items
Hello,
I´m adding maybe 2-500 items into a Listview and its very slow...
Anyone know a resolutiion to this problem....
My code is very plain just a For loop which adds items while the recordset is not EOF ... so i don´t really know what could be wrong ....
Thanks in advance
vanki
-
Jan 8th, 2003, 04:27 PM
#2
Hyperactive Member
Hi vanki
How about popping a copy of your code here for us to take a look at.
-
Jan 8th, 2003, 05:53 PM
#3
New Member
The problem might be that every time you add an item, the listview redraws itself, which can take a while. Before the loop, call the listview's beginUpdate() method and after the loop call its EndUpdate() method.
-
Jan 8th, 2003, 06:01 PM
#4
Thread Starter
New Member
Code
For Each oResult In oSearch.SearchResults
System.Windows.Forms.Application.DoEvents()
lstvResults.BeginUpdate()
If bStop = True Then
Exit For
End If
Dim itmX As New ListViewItem()
Dim s As Integer
If oCols.Item(0).Name = "Size" Then
itmX.Text = CInt(oResult.Fields.Item(oCols.Item(0).Name).Value / 1024) & "KB"
Else
itmX.Text = CStr(oResult.Fields.Item(oCols.Item(0).Name).Value)
End If
itmX.Tag = oResult.DocumentID
If oResult.Extension = ".msg" Then
itmX.ImageIndex = 10
ElseIf oResult.Extension = ".doc" Then
itmX.ImageIndex = 8
ElseIf oResult.Extension = ".xls" Then
itmX.ImageIndex = 9
ElseIf oResult.Extension = ".ppt" Then
itmX.ImageIndex = 18
ElseIf oResult.Extension = ".mdb" Then
itmX.ImageIndex = 20
ElseIf oResult.Extension = ".gif" Or oResult.Extension = ".jpg" Or oResult.Extension = ".tif" Or oResult.Extension = ".bmp" Then
itmX.ImageIndex = 22
ElseIf oResult.Extension = ".pdf" Then
itmX.ImageIndex = 24
Else
itmX.ImageIndex = 13
End If
If oCols.Count() = 1 Or oCols.Count > 1 Then
For s = 1 To oCols.Count - 1
If oCols.Item(s).Name = "Size" Then
itmX.SubItems.Add(CInt(oResult.Fields.Item(oCols.Item(s).Name).Value / 1024) & "KB")
Else
itmX.SubItems.Add(CStr(oResult.Fields.Item(oCols.Item(s).Name).Value))
End If
Next
End If
lstvResults.Items.Add(itmX)
lstvResults.EndUpdate()
prgrBar.PerformStep()
counter = counter + 1
Next
-
Jan 9th, 2003, 02:16 AM
#5
Registered User
I agree with DSAINMON and I think the beginupdate and endupdate is good to check, but you have to keep it outside the loop, not inside as you are now. Now you are calling the methods for every round of the loop, saving nothing.
-
Jan 9th, 2003, 11:24 AM
#6
Thread Starter
New Member
BeginUpdate ....EndUpdate
I tried the BeginUpdate and EndUpdate and put it ouside of the for loop but it makes no difference ....
-
Jan 9th, 2003, 11:59 AM
#7
You should also remove the DoEvents which will slow it down a lot.
VB Code:
[b]lstvResults.BeginUpdate()[/b]
For Each oResult In oSearch.SearchResults
[b]'System.Windows.Forms.Application.DoEvents()[/b]
If bStop = True Then
Exit For
End If
Dim itmX As New ListViewItem()
Dim s As Integer
If oCols.Item(0).Name = "Size" Then
itmX.Text = CInt(oResult.Fields.Item(oCols.Item(0).Name).Value / 1024) & "KB"
Else
itmX.Text = CStr(oResult.Fields.Item(oCols.Item(0).Name).Value)
End If
itmX.Tag = oResult.DocumentID
If oResult.Extension = ".msg" Then
itmX.ImageIndex = 10
ElseIf oResult.Extension = ".doc" Then
itmX.ImageIndex = 8
ElseIf oResult.Extension = ".xls" Then
itmX.ImageIndex = 9
ElseIf oResult.Extension = ".ppt" Then
itmX.ImageIndex = 18
ElseIf oResult.Extension = ".mdb" Then
itmX.ImageIndex = 20
ElseIf oResult.Extension = ".gif" Or oResult.Extension = ".jpg" Or oResult.Extension = ".tif" Or oResult.Extension = ".bmp" Then
itmX.ImageIndex = 22
ElseIf oResult.Extension = ".pdf" Then
itmX.ImageIndex = 24
Else
itmX.ImageIndex = 13
End If
If oCols.Count() = 1 Or oCols.Count > 1 Then
For s = 1 To oCols.Count - 1
If oCols.Item(s).Name = "Size" Then
itmX.SubItems.Add(CInt(oResult.Fields.Item(oCols.Item(s).Name).Value / 1024) & "KB")
Else
itmX.SubItems.Add(CStr(oResult.Fields.Item(oCols.Item(s).Name).Value))
End If
Next
End If
lstvResults.Items.Add(itmX)
prgrBar.PerformStep()
counter = counter + 1
Next
[b]lstvResults.EndUpdate()[/b]
-
Jan 9th, 2003, 12:01 PM
#8
Thread Starter
New Member
need it :)
I need the DoEvents so the user can stop the process
-
Jan 9th, 2003, 12:05 PM
#9
I think you may be stuck with it being slow then, especially if its 500 items. Or maybe only do events on every third item or every 5 items or something. See DoEvents has to check and let all other system processes run so it is checking on EVERY item and slowing you down.
-
Jan 9th, 2003, 12:08 PM
#10
Thread Starter
New Member
well...
I tried to comment out the DoEvents .... but the speed doesnt change at all
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
|