BUG in ListView - throws exceptions when adding items

G

Guest

There is a bug with the ListView control which is revelead when calling
Application.EnableVisualStyles(). To reproduce follow these steps...

- Create a new winforms app
- Add call to Application.EnableVisualStyles() before Application.Run()
- Add a ListView control and a button to the form
- In the button click handler, add 3 items to the listview items collection

Now go to "Debug...Exceptions" and set the debugger to break on any CLR
exception. Run in the debugger.

When you click the button, you'll see 6 "ArgumentOutOfRange" exceptions
thrown (2 per item)! They are caught inside the method, but this is still a
bug... it should not throw... because:

(a) this causes my application to run very slowly in debug mode (lots of
items)
(b) no exceptions are thrown if EnableVisualStyles() is not called

Does anyone know a workaround?
 
H

Herfried K. Wagner [MVP]

* "=?Utf-8?B?R3JlZyBFbm5pcw==?= said:
There is a bug with the ListView control which is revelead when calling
Application.EnableVisualStyles(). To reproduce follow these steps...

- Create a new winforms app
- Add call to Application.EnableVisualStyles() before Application.Run()
- Add a ListView control and a button to the form
- In the button click handler, add 3 items to the listview items collection

Now go to "Debug...Exceptions" and set the debugger to break on any CLR
exception. Run in the debugger.

When you click the button, you'll see 6 "ArgumentOutOfRange" exceptions
thrown (2 per item)! They are caught inside the method, but this is still a
bug... it should not throw... because:

(a) this causes my application to run very slowly in debug mode (lots of
items)
(b) no exceptions are thrown if EnableVisualStyles() is not called

Does anyone know a workaround?

I am only able to tell you that I can repro the exceptions on my Windows
XP Professional machine running .NET 1.1.
 
T

Tom Dacon

This isn't the only problem that EnableVisualStyles can give you. Consider
doing your visual styles the 'old-fashioned way', with a manifest.

I hope that MS does some work on EnableVisualStyles for the next release or
service pack.

Tom Dacon
Dacon Software Consulting
 

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