The (slow) tree control I use in my addins


Back when was working on my text file importer and the Project Gutenberg addin (, I mentioned the tree control I used to allow you to choose where you wanted the data to go in OneNote once imported.  Performance of this control was not a consideration, and you may have noticed it can run a little slow if you have many (on the order of dozens) of notebooks.


I knew it was a slow method I used.  That did not bother me too much, and I wanted to explain why.


Mostly, I create this toys/addins when I have "free" time available.  I use them to learn our extensibility API.  My focus is mostly on the API itself - working through the parameter lists, iterating through the XML hierarchy, working with the different data types we store, node names, etc…  While I could try to optimize the data population of this common control, that is not the primary task at hand.


Also, this was a quick, easy and tested solution to the problem at hand.  All I wanted to do was allow a way to choose where to store the information in OneNote.  When I went to MSDN to look up the properties on the tree control which ships with Visual Studio, I stumbled across this article:  This was almost exactly what I needed.  Since "sample code" and "templates" are now nearly synonymous, I just "cut and paste" this code to overcome the hurdle I had.  The code had already been tested before being posted, so I was comfortable with that aspect.  I did not have the time to recreate this particular wheel, and I did not have time to test my own code.  The quick and easy solution won.


Finally, though, the perf was pretty poor when I first tested my applications.  I would normally load the entire XML document which goes to the page level.  Since there are so many pages, this was incredibly slow.  If you look at my final code, you will notice I only delve to the section level to avoid the overhead of loading the page details.


Then, once I am comfortable with having learned what I set out to learn, I decided to give these toys/addins away. 


As always, comments welcome,


Skip to main content