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

Re: ListView taking a long time to select. by hirf-spam-me-here

hirf-spam-me-here
Wed Jun 02 11:26:09 CDT 2004

* =?Utf-8?B?S2V2aW4gQnVydG9u?= <anonymous@discussions.microsoft.com> scripsit:
> 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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Re: ListView taking a long time to select. by anonymous

anonymous
Wed Jun 02 11:51:02 CDT 2004

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?= <anonymous@discussions.microsoft.com> scripsit
> 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
>> 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 hat
> 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

--
Herfried K. Wagner [MVP
<URL:http://dotnet.mvps.org/>

Re: ListView taking a long time to select. by anonymous

anonymous
Wed Jun 02 14:26:08 CDT 2004

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()