Having a very odd problem with an imagelist?

  • Thread starter Andrew Christiansen
  • Start date
A

Andrew Christiansen

Hey everyone. I have Visual Basic .NET 2003 and am trying to show images on
a treeview control. I have the imagelist on the form filled with images,
and have the ImageList property of the treeview control set to the imagelist
containing the images I want to be displayed next to each node.

It seems that no matter what I do there will be no images displayed next to
the nodes during runtime. I tried creating nodes during designtime using
the Nodes property, and the image appears next to the node in the designer
like it should, but when I run the app, there's no image visible, just a
blank space where the image is supposed to be followed by the node text.
Does this even when I add nodes at runtime, using code:

MyTreeview.Nodes.Add(New TreeNode("Node text", 0, 0))
0 is the index of the image in the imagelist that I want displayed.

I just noticed it does this with everything that uses the imagelist! The
toolbar, listview, treeview; everything behaves the same.

Also, this didn't always be a problem. It started acting this way when I
cut and pasted an imagelist control to a different form in one of my
projects. Its not a project-specific problem either, because I started a
new project and it does the same thing. I've tried restarting, running a
repair installation on VB.NET, nothing will fix it.

Even when I run the compiled app on another PC, same thing.

Anyone else having this weird problem? It's becoming very frustrating, and
would love to hear anyone's ideas. Thanks a lot.

Andrew
 
K

Ken Tucker [MVP]

Hi,

I had a similar problem with a toolbar a while ago. Look in the
Windows Form Designer generated code region. Make sure the imagelist is
created before the treeview.

Ken
 
A

Andrew Christiansen

Tried that just now. I was excited because it sounded like it would solve
the problem, doesn't. I moved the block of code that sets the properties of
the imagelist:

'
ImageList1
'
Blah .........

Above where the listview is, and still no luck. Dang I'm getting very
frusterated I can't really do much of anything until I get this fixed, I've
been working on this problem for like 3 days now. Any other ideas? Is that
all you did to fix the toolbar problem you had? Thanks.

Andrew
 
J

Jared

I had the same problem when I used Application.EnableVisualStyles, my
existing toolbar icons didn't display their icons.
Another thing, the depth of the image may not be supported by your video
card, check the depth property of the image in the imagelist. Just some
extra suggestions.
 
A

Andrew Christiansen

Wow, I commented out the Application.EnableVisualStyles method that I was
calling in Sub Main() and, voulia, the image was there. Hmmm.... should I
call EnableVisualStyles elsewhere to keep it from doing that? Thanks!

Andrew
 
A

Andrew Christiansen

Figured it out! For everyone having this problem, call Application.DoEvents
right after calling EnableVisualStyles, it will enable the styles plus keep
the images intact. I have no idea why calling DoEvents fixes the problem,
but it does. The article I read that told me this said that there was
probably some message that gets filtered out upon calling EnableVisualStyles
that keeps the images from being visible, but when you call DoEvents the
message gets processed. Makes sense.

Thanks.

Andrew
 
C

Cor

Hi Andrew,

That is greath this message because this is a workaround for what I thought
I have often seen in this newsgroup mentioned as something that was
imposible.

Cor
 
J

Jared

Sorry, should have told you to use the DoEvents after EnbaleVisualStyles. I
thought the documentation said you should always do it. I must have started
using it when I first had the problem and just made it mandatory in my mind.
I guess I could have saved you a little time. Sorry about that.

Jared
 

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

Similar Threads

treeview and imagelist 1
Image index. 1
Treeview/ImageList in a User Control 1
SelectedImageIndex in Treeview 1
imagelist and treeview 1
Treenode image problem bug? 5
Understanding ImageList 2
ImageList issue 5

Top