<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How to insert a large number of items into a treeview efficiently</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2011/11/25/10241394.aspx</link><description>Just a quick tip.</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: How to insert a large number of items into a treeview efficiently</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2011/11/25/10241394.aspx#10243345</link><pubDate>Thu, 01 Dec 2011 14:35:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10243345</guid><dc:creator>JA</dc:creator><description>&lt;p&gt;And this is why I am burning out on Windows programming, having to know minutia such as this in order to excel is getting old.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10243345" width="1" height="1"&gt;</description></item><item><title>re: How to insert a large number of items into a treeview efficiently</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2011/11/25/10241394.aspx#10242603</link><pubDate>Tue, 29 Nov 2011 22:43:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10242603</guid><dc:creator>.dan.g.</dc:creator><description>&lt;p&gt;Thanks Raymond, I implemented your suggested solution (requiring changes to 6 lines of code) and whatever the speed benefits are it&amp;#39;s got to be better than nothing!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10242603" width="1" height="1"&gt;</description></item><item><title>re: How to insert a large number of items into a treeview efficiently</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2011/11/25/10241394.aspx#10242440</link><pubDate>Tue, 29 Nov 2011 15:51:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10242440</guid><dc:creator>KS</dc:creator><description>&lt;p&gt;@Raymond: You have only 6 Favorites? Good for you. The average user has a few hundred (not tens of thousands, of course), sometimes organized in several folder levels. Now imagine what happens in a combobox with all that expanded ...&lt;/p&gt;
&lt;div class="post"&gt;[&lt;i&gt;I have plenty of favorites. But the combo box in question doesn&amp;#39;t show all the favorites; only the folders. And I organize my favorites into just 6 folders. If you created hundreds of folders to organize your favorites, then you&amp;#39;ve basically said &amp;quot;You know what, I like seeing hundreds of things at once - bring it on!&amp;quot; -Raymond&lt;/i&gt;]&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10242440" width="1" height="1"&gt;</description></item><item><title>re: How to insert a large number of items into a treeview efficiently</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2011/11/25/10241394.aspx#10242162</link><pubDate>Mon, 28 Nov 2011 21:33:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10242162</guid><dc:creator>Adrian</dc:creator><description>&lt;p&gt;When writing a backwards counting loop, you have to be careful if your loop index is unsigned. &amp;nbsp;As more programmers use STL containers, which use std::size_t for size(), it becomes more common for indexes to be unsigned types. &amp;nbsp;A downward counting loop is a tad safer written as:&lt;/p&gt;
&lt;p&gt;for (i = array.Count(); i &amp;gt; 0; ) {&lt;/p&gt;
&lt;p&gt; &amp;nbsp;--i;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;// loop body here&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;This idiom works whether the index is signed or unsigned.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10242162" width="1" height="1"&gt;</description></item><item><title>re: How to insert a large number of items into a treeview efficiently</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2011/11/25/10241394.aspx#10242016</link><pubDate>Mon, 28 Nov 2011 15:00:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10242016</guid><dc:creator>Kelden</dc:creator><description>&lt;p&gt;In VB6, you can insert 50k items in about 1 second. But if you try to close the window, it takes about 25 seconds to destroy the window.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10242016" width="1" height="1"&gt;</description></item><item><title>re: How to insert a large number of items into a treeview efficiently</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2011/11/25/10241394.aspx#10241815</link><pubDate>Sun, 27 Nov 2011 19:18:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10241815</guid><dc:creator>Mehrdad</dc:creator><description>&lt;p&gt;Cool post!&lt;/p&gt;
&lt;p&gt;But why is it _slower_ to destroy the window afterward, if you insert things backward?&lt;/p&gt;
&lt;div class="post"&gt;[&lt;i&gt;The order of insertion should have no effect on destruction performance. The treeview doesn&amp;#39;t remember what order you inserted them. -Raymond&lt;/i&gt;]&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10241815" width="1" height="1"&gt;</description></item><item><title>re: How to insert a large number of items into a treeview efficiently</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2011/11/25/10241394.aspx#10241775</link><pubDate>Sun, 27 Nov 2011 10:29:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10241775</guid><dc:creator>Neil</dc:creator><description>&lt;p&gt;If you thought a large combobox was bad, then consider the case of a large popup menubutton - you don&amp;#39;t have a scrollbar, nor any indication of the current item in the list. (Yes, this was an application badly ported from the Mac.)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10241775" width="1" height="1"&gt;</description></item><item><title>re: How to insert a large number of items into a treeview efficiently</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2011/11/25/10241394.aspx#10241624</link><pubDate>Fri, 25 Nov 2011 21:19:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10241624</guid><dc:creator>Phaeron</dc:creator><description>&lt;p&gt;Having run into this problem before, the counterpoints I would make are that:&lt;/p&gt;
&lt;p&gt;1) You can see this performance issue with about a thousand nodes, which isn&amp;#39;t that bad to browse if the tree view is full screen height.&lt;/p&gt;
&lt;p&gt;2) You don&amp;#39;t always have enough control over the data that you receive.&lt;/p&gt;
&lt;p&gt;3) In my view, it&amp;#39;s sub-optimal design for a UI control to have O(N^2) insertion performance when populated in natural order.&lt;/p&gt;
&lt;p&gt;The danger with having an O(N^2) situation like this is that it doesn&amp;#39;t just make the program slow as N grows large but instead it makes the program unusable. Since a tree view is often used for the top-level view of data, the alternatives for shortening the node list aren&amp;#39;t great -- both chunking into intermediate nodes and &amp;quot;display more&amp;quot; links seem more awkward to me from a usability standpoint.&lt;/p&gt;
&lt;p&gt;I did notice that this performance issue is now documented in MSDN, though, which is good.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10241624" width="1" height="1"&gt;</description></item><item><title>re: How to insert a large number of items into a treeview efficiently</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2011/11/25/10241394.aspx#10241620</link><pubDate>Fri, 25 Nov 2011 20:51:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10241620</guid><dc:creator>CarlD</dc:creator><description>&lt;p&gt;&amp;quot;You&amp;#39;ll probably want to consider a better way of presenting the information than in a tree view that goes on for hundreds of screens.&amp;quot;&lt;/p&gt;
&lt;p&gt;Or a combo box that tries to cram 10,000 items into a scrollable, non-searchable drop-down!&lt;/p&gt;
&lt;p&gt;Unfortuantely, sometimes you have no choice: e.g. a query-based parameter in SSRS allows for one UI representation: &amp;nbsp;a combo box, regardless of how many items might be presented. &amp;nbsp;It is truly a horrible UI experience.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10241620" width="1" height="1"&gt;</description></item><item><title>re: How to insert a large number of items into a treeview efficiently</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2011/11/25/10241394.aspx#10241614</link><pubDate>Fri, 25 Nov 2011 20:03:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10241614</guid><dc:creator>acq</dc:creator><description>&lt;p&gt;&amp;quot;Given that a treeview is, well, a tree structure, it&amp;#39;s not clear what &amp;quot;after&amp;quot; means when applied to a tree as a whole&amp;quot;&lt;/p&gt;
&lt;p&gt;I agree. For me it was also unclear that hInsertAfter can even be &amp;quot;TVI_ROOT: Add the item as a root item.&amp;quot; Why that?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10241614" width="1" height="1"&gt;</description></item></channel></rss>