.NET TreeView will not display images

Problem getting TreeView control to display node images. The code below sometimes works, but at other times the image is not displayed.


private TreeNode AddNodeForCore(TreeNode root, Core c) {
    string key = GetImageKey(c);
    TreeNode t = root.Nodes.Add(c.Name, c.Name, key, key);
    t.Tag = c;
    return t;
}

Note that on failure, TreeView cannot display images for any node. TreeView has an ImageList assigned to it, and the image key is definitely in the image collection.

Edit:
My google-fu is weak. I can’t believe that I myself did not find this answer.

+5
source share
4 answers

The useful bit of the above messages is actually:

" Windows XP. , ImageList, , , Application.EnableVisualStyles(). Main() # Program.cs . !"

, , , Application.EnableVisualStyles() , .

+8

Google : http://forums.microsoft.com/MSDN/ShowPost.aspx?siteid=1&PostID=965968

:

, TreeView, , , !

public partial class ThisApplication
{
    Form1 frm;

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

    }

, , :

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


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

    }

. , "VisualStyles" ( XP) , .

+2

[ ] (http://msdn.microsoft.com/en-us/library/ydx6whxs(VS.80).aspx) MSDN TreeView.ImageList, TreeView.SelectedImageList .

, node, .

+1

, Yossarian, Call Application.DoEvents() Application.EnableVisualStyles() Application.Run(), .

, Googling , Addy Santo, .

0

All Articles