Hi,
I have been testing a form with a tree control with a couple of 100 nodes. Each node has a single image.
I was using an imagelist with mainly .ico files in that imagelist. I was using LeftImages.Add.
I changed all the code to be Override.NodeAppeareance.Image = resourceSomePicture.pngName.
Now:
1) The form takes a very long time to load
2) if i close and open the form a few times i get out of memory errors.
What is the right way to do this? ImageLIst? Resource File? LeftImages? NodeAppearance?
Why the memory errors? Do I need to do something special on the dispose event of the form?
Thanks,
Mel
I have been testing this and so far using the left.images add with an imagelist has been most effecient. What Mike said makes a lot of sense and has me re-thinking how to handle the settings for controls throughout the application. All of our combo boxes for instance look and behave the same. I notice that in the code behind if i manually make a change to that control it creates a sepearate appearance object for each setting. If i create a global appearance for the form or even the project I can just set it to that control.
Thanks for the help.
Hello Mel,
I am checking about the progress of this issue. Please let me know If you need any further assistance on this.
I am pretty sure that using images from a resx like you are doing here creates a new Image object every time you ask for it. So every time you reference resourceSomePicture.pngName, you are creating a new image object that contains the same image information. So one way to get around this would be to cache the image in a variable and re-use it.
Also, using Override.NodeAppeareance.Image is very inefficient. The NodeAppearance property is lazily created. So by doing this, you are creating a new Appearance object for every node in the tree. A much more efficient way to handle this would be to create an Appearance object with the image you want and assign that NodeAppearance property to your Appearance. That way you create and re-use a single Appearance object instead of one for every node.
Could you please try to attach if possible a small sample project reproducing the above mentioned issue since I am not able to do so, I will be happy to take a look at it.
Well now I am adding the images via LeftImages.Add and an image list but still get out of memory (specifically on lines that add the image) when i clear and recreate the tree.
What is the right way to do this and do I need to do anything other than Nodes.Clear()?
Thanks,Mel