March 28, 2006

No Images in a TreeView

OK, right this one up under lame fixes.

This is the setup: WinForms with a TreeView and an ImageList. What happens: no images in the TreeView. Totally blank!

The culprit: Application.EnableVisualStyles.

If your Main() looks like this:
Application.EnableVisualStyles(); Application.Run(new frmMain());
You will not see Images in your TreeView no matter how hard you try.

But change it ever so slightly to this:
Application.EnableVisualStyles(); Application.DoEvents(); Application.Run(new frmMain());
and everything is hunky dorry.

BTW: I take no credit in figuring this out. I actually found the fix in the Microsoft .NET VB Forums.

No comments: