Matthieu LABAN
.NET, My Life, Flight Simulation and Real Flight...

 
About Me :
25 Years old developer and aviation
enthusiast living in Santa Clara, California.
View Matthieu Laban's profile on LinkedIn 
Contact me at :
mlaban at gmail dot com


Photo & Video Galleries:
- Gallery List
- Flight Videos
Resume :
e-mail me to get my latest résumé
ImageList not set on WinForms controls like ListView, ToolBar, TreeView ... 

[This entry has been imported from my old blog, therefore, links and images might now show correctly. Sorry about that]

I haven't posted for a while, so i'm going to write a little thing that might help my fellow Winforms designers ...

A while ago, i had a problem with a Treeview, i assigned an ImageList to the items in my treeview, and the images were correctly displayed next to the TreeNodes at design time ... but at runtime, i couldn't get the damn images to show up !

If you are using this combinaison of controls, you will eventually face this problem, which is actually another bug of our favorite IDE, Visual Studio...
The bug resides in the fact that controls are initialized in the InitializeComponent method in a alphabetical order (for some, not all.. why ??) ...
This leads to the following problem, a ListView control will be assigned its ImageList, and then, the imagelist will be filled with the images set in the designer ... For some reason, the images are all blank, when shown in the control, so here is a little workaround, all you need to do, is after the InitializeComponent call in the class Constructor, do the following :


myList.ImageList = null;
myList.ImageList = myImageList;


et voilà ! it works !

Happy Flyings people, and let's hope the SP1 of Visual Studio 2003 will correct all these annoying problems we face weekly with the Visual Studio Designer ...