ListView taking a long time to select.

G

Guest

I have a ListView that I am showing in 'Detail' mode. The list contains about 740 items and I have a button that tries to go through all items in the list and select them and change the image icon. This seems to take over a minute or two just to do something like

foreach(ListViewItem item in listView.Items

item.Selected = true
item.ImageIndex = 1


Does anyone have any suggestions on how to speed this up? I would hate to guess how long it would take if I had 7000 items in the list. What is taking so long? I have tried to suspend the layout as is done during the Windows initialization but this did not seem to have any effect

Thank you for your suggestions

Kevin
 
H

Herfried K. Wagner [MVP]

* =?Utf-8?B?S2V2aW4gQnVydG9u?= said:
I have a ListView that I am showing in 'Detail' mode. The list
contains about 740 items and I have a button that tries to go through
all items in the list and select them and change the image icon. This
seems to take over a minute or two just to do something like:

foreach(ListViewItem item in listView.Items)
{
item.Selected = true;
item.ImageIndex = 1;
}

Does anyone have any suggestions on how to speed this up? I would hate
to guess how long it would take if I had 7000 items in the list. What is
taking so long? I have tried to suspend the layout as is done during the
Windows initialization but this did not seem to have any effect.

Have a look at the control's 'BeginUpdate' and 'EndUpdate' methods.
'SuspendLayout' doesn't have any influence in this case because no
layouting (repositioning of controls) is done.
 
G

Guest

Thank you for your suggestion. But this did not help. The exact code that I am executing is

cardholderList.BeginUpdate()
resetProgressBar.Minimum = 0
resetProgressBar.Maximum = cardholderList.Items.Count
resetProgressBar.Step = 1
resetProgressBar.Value = 0
foreach(ListViewItem item in cardholderList.Items

item.Selected = true
item.ImageIndex = 1
resetProgressBar.PerformStep()

cardholderList.EndUpdate()

I have tried it with and without the progress bar. It seems to take equally long

Kevi

----- Herfried K. Wagner [MVP] wrote: ----

* =?Utf-8?B?S2V2aW4gQnVydG9u?= said:
I have a ListView that I am showing in 'Detail' mode. The lis
contains about 740 items and I have a button that tries to go throug
all items in the list and select them and change the image icon. Thi
seems to take over a minute or two just to do something like

item.Selected = true
item.ImageIndex = 1

to guess how long it would take if I had 7000 items in the list. What i
taking so long? I have tried to suspend the layout as is done during th
Windows initialization but this did not seem to have any effect

Have a look at the control's 'BeginUpdate' and 'EndUpdate' methods
'SuspendLayout' doesn't have any influence in this case because n
layouting (repositioning of controls) is done
 
G

Guest

As an update I ran the code through a profiler and found that setting the 'Selected' to true (item.Selected = true) was taking 98% of the time. There seems to be alot of overhead with this call. Is there a faster way of setting an item 'Selected'

Kevi

cardholderList.BeginUpdate()
resetProgressBar.Minimum = 0
resetProgressBar.Maximum = cardholderList.Items.Count
resetProgressBar.Step = 1
resetProgressBar.Value = 0
foreach(ListViewItem item in cardholderList.Items

item.Selected = true
item.ImageIndex = 1
resetProgressBar.PerformStep()

cardholderList.EndUpdate()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top