ListView and ImageList problem - disappearing icons between runs.

R

Rik Hemsley

Hi,

I'm using a ListView in Details mode and have assigned an ImageList to
it via its SmallImageList property.

If I make a trivial change to the code of my application, and then run
it, the images show up within the ListViewItems as expected.

The next time, and each subsequent time, that I run my application
(through the VS.NET 2003 debugger or compiled and outside VS.NET), the
images do not appear. It appears that display space is reserved for
them, but they show as blank.

If I make another trivial change (such as clearing a list which has just
been created), the images will be displayed in the next run of the
application.

This behaviour is quite consistent, though on a few occasions I have
managed to run the application twice before the icons start disappearing.

The images are loaded from embedded resources and I have checked with
the debugger that they are always loaded correctly and added to the
ImageList.

I cannot fathom how it is possible for this problem to occur only on the
second and subsequent runs after a compile.

A trivial test application does not have the same problem.

Rik
 
H

Herfried K. Wagner [MVP]

Rik Hemsley said:
I'm using a ListView in Details mode and have assigned an ImageList to it
via its SmallImageList property.

If I make a trivial change to the code of my application, and then run it,
the images show up within the ListViewItems as expected.

Are you using 'Application.EnableVisualStyles' in your application? If you
do so, call 'Application.DoEvents' immediately after calling
'EnableVisualStyles'.
 
R

Rik Hemsley

Herfried said:
Are you using 'Application.EnableVisualStyles' in your application? If you
do so, call 'Application.DoEvents' immediately after calling
'EnableVisualStyles'.

I already do that, but thanks anyway!

Rik
 
R

Rik Hemsley

Herfried said:
Are you using 'Application.EnableVisualStyles' in your application? If you
do so, call 'Application.DoEvents' immediately after calling
'EnableVisualStyles'.

The DoEvents didn't fix it (I already had it) but getting rid of
EnableVisualStyles did.

Now my application looks completely out of place on XP and Server 2003
but at least it's functional!

Thanks for pointing me in the right direction.

Rik
 
R

Rik Hemsley

Rik said:
The DoEvents didn't fix it (I already had it) but getting rid of
EnableVisualStyles did.

For anyone who's had a similar problem: If you ensure that
EnableVisualStyles is _first_ in your Main(), then that fixes the
problem I had while still allowing the XP styling to work.

I think my problem was that I was showing a splash screen before calling
EnableVisualStyles.

Rik
 
H

Herfried K. Wagner [MVP]

Rik Hemsley said:
I think my problem was that I was showing a splash screen before calling
EnableVisualStyles.

Well, that would have been my next suggestion ;-).
 

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