Windows Develop Bookmark and Share   
 index > Windows Forms General > TreeView fails to display icons, why?
 

TreeView fails to display icons, why?

**also posted to VSTO form...no replies **

My VSTO Outlook add-in shows a form with a TreeView control. The tree works properly, showing the data I expect it to, but not the icon images.

When I add a default root node in VS Designer and assign it an image from my ImageList, it appears correctly in the designer. When I run the add-in, the default node appears, but without icon.

There was a related threadMSDN Forums » Windows Forms » Windows Forms General » Icons not showing up on TreviewonVSTO beta, but no real answer posted. Anyone have any ideas?

The debugger shows that the TreeView object does have the ImageList, and that the ImageList has the right number of images, and that the nodes have ImageIndex values in the proper range.

--Allen


Allen Razdow  Tuesday, November 28, 2006 2:50 PM

Thanks to Microsoft Support, the mystery is solved.

If the Form containing the TreeView is instantiated in the add-in startup function as below, the icons appear!

public partial class ThisApplication
{
Form1 frm;

private void ThisApplication_Startup(object sender, System.EventArgs e)
{
frm = new Form1();
frm.Show();

}

BUT, if instantiated with the class, as below:

public partial class ThisApplication
{
Form1 frm = new Form1();


private void ThisApplication_Startup(object sender, System.EventArgs e)
{
frm.Show();

}

Then they do NOT appear. Furthermore, if "VisualStyles" (new with XP) are disabled, the icons work in both instances.

-Allen

Allen Razdow  Friday, December 01, 2006 7:12 PM

Thanks to Microsoft Support, the mystery is solved.

If the Form containing the TreeView is instantiated in the add-in startup function as below, the icons appear!

public partial class ThisApplication
{
Form1 frm;

private void ThisApplication_Startup(object sender, System.EventArgs e)
{
frm = new Form1();
frm.Show();

}

BUT, if instantiated with the class, as below:

public partial class ThisApplication
{
Form1 frm = new Form1();


private void ThisApplication_Startup(object sender, System.EventArgs e)
{
frm.Show();

}

Then they do NOT appear. Furthermore, if "VisualStyles" (new with XP) are disabled, the icons work in both instances.

-Allen

Allen Razdow  Friday, December 01, 2006 7:12 PM
This is a known bug in the Windows XP visual styles implementation. Certain controls, like ImageList, do not get properly initialized when they've been created before the app calls Application.EnableVisualStyles(). The normal Main() implementation in a C#'s Program.cs avoids this. Thanks for posting back!

nobugz  Friday, December 01, 2006 9:08 PM
Ohhh!!

The example code I found everywhere didn't fit my problem.

but these words helpd so I called Application.EnableVisualStyles(). BEFORE creating the form containing the treeview


Application.EnableVisualStyles(); // << Must come first
theAuxTreeForm = new FormTreeMap; // Form that contains the treeview
////Application.EnableVisualStyles(); // << no icons images in the tree if only enabled here
theMainForm= new FormMain;
Application.Run(theMainForm);
HopelessInSeattle  Wednesday, September 16, 2009 6:59 PM

You can use google to search for other answers

Custom Search

More Threads

• Delete listview item on delete key press?
• Datagridview problem with combobox column
• How to get the depths of TreeNode in C# Code without Click event ?
• Alt Key Usage
• How to focus a text for mouse hover event?
• BorderStyle for Datagridviewtextbox column
• Windows Defender detects and removes spyware
• VB.NET Windows Application
• how to create a system DSN for SQL Server in .NET
• Tabbed forms...