<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" > <channel><title>Comments on: Selecting an item in a TreeView in WPF</title> <atom:link href="http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/feed/" rel="self" type="application/rss+xml" /><link>http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/</link> <description>Straight from the mind of geniuseseses....</description> <lastBuildDate>Thu, 26 Jan 2012 20:48:40 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>By: Haim</title><link>http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/comment-page-1/#comment-12609</link> <dc:creator>Haim</dc:creator> <pubDate>Wed, 23 Nov 2011 14:22:06 +0000</pubDate> <guid isPermaLink="false">http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/#comment-12609</guid> <description>Thanks, this was very helpful I changed the function SetSelectedItem to take TreeViewItem instead of TreeView since I knew the level of the tree I needed to search to take place SetSelectedItem(TreeViewItem treeViewItem, object item)</description> <content:encoded><![CDATA[<p>Thanks, this was very helpful<br /> I changed the function SetSelectedItem to take TreeViewItem instead of TreeView since I knew the level of the tree I needed to search to take place SetSelectedItem(TreeViewItem treeViewItem, object item)</p> ]]></content:encoded> </item> <item><title>By: Roman Łubkowski</title><link>http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/comment-page-1/#comment-12605</link> <dc:creator>Roman Łubkowski</dc:creator> <pubDate>Thu, 17 Nov 2011 21:47:47 +0000</pubDate> <guid isPermaLink="false">http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/#comment-12605</guid> <description>Thanks for the code. You really saved my ass!!!</description> <content:encoded><![CDATA[<p>Thanks for the code. You really saved my ass!!!</p> ]]></content:encoded> </item> <item><title>By: Christian</title><link>http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/comment-page-1/#comment-12566</link> <dc:creator>Christian</dc:creator> <pubDate>Wed, 07 Sep 2011 10:27:31 +0000</pubDate> <guid isPermaLink="false">http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/#comment-12566</guid> <description>Thanks a lot, works perfect ;)</description> <content:encoded><![CDATA[<p>Thanks a lot, works perfect ;)</p> ]]></content:encoded> </item> <item><title>By: combuilder</title><link>http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/comment-page-1/#comment-12562</link> <dc:creator>combuilder</dc:creator> <pubDate>Fri, 02 Sep 2011 21:11:19 +0000</pubDate> <guid isPermaLink="false">http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/#comment-12562</guid> <description>I tried your code but i cannot do it work when some &quot;items&quot; (nodes) are not treeviewitem. Any help will be appreciate</description> <content:encoded><![CDATA[<p>I tried your code but i cannot do it work when some &#8220;items&#8221; (nodes) are not treeviewitem. Any help will be appreciate</p> ]]></content:encoded> </item> <item><title>By: Gerrod</title><link>http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/comment-page-1/#comment-12528</link> <dc:creator>Gerrod</dc:creator> <pubDate>Thu, 28 Jul 2011 21:18:40 +0000</pubDate> <guid isPermaLink="false">http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/#comment-12528</guid> <description>Hi Matt - not sure why it doesn&#039;t copy and paste properly... try this:static public bool SetSelectedItem( this TreeView treeView, object item) { return SetSelected(treeView, item); } static private bool SetSelected(ItemsControl parent, object child) { if (parent == null &#124;&#124; child == null) { return false; } TreeViewItem childNode = parent.ItemContainerGenerator .ContainerFromItem(child) as TreeViewItem; if (childNode != null) { childNode.Focus(); return childNode.IsSelected = true; } if (parent.Items.Count &gt; 0) { foreach (object childItem in parent.Items) { ItemsControl childControl = parent .ItemContainerGenerator .ContainerFromItem(childItem) as ItemsControl; if (SetSelected(childControl, child)) { return true; } } } return false; }</description> <content:encoded><![CDATA[<p>Hi Matt &#8211; not sure why it doesn&#8217;t copy and paste properly&#8230; try this:</p><p>static public bool SetSelectedItem(<br /> this TreeView treeView, object item) {</p><p> return SetSelected(treeView, item);<br /> }</p><p>static private bool SetSelected(ItemsControl parent,<br /> object child) {</p><p> if (parent == null || child == null) {<br /> return false;<br /> }</p><p> TreeViewItem childNode = parent.ItemContainerGenerator<br /> .ContainerFromItem(child) as TreeViewItem;</p><p> if (childNode != null) {<br /> childNode.Focus();<br /> return childNode.IsSelected = true;<br /> }</p><p> if (parent.Items.Count &gt; 0) {<br /> foreach (object childItem in parent.Items) {<br /> ItemsControl childControl = parent<br /> .ItemContainerGenerator<br /> .ContainerFromItem(childItem)<br /> as ItemsControl;</p><p> if (SetSelected(childControl, child)) {<br /> return true;<br /> }<br /> }<br /> }</p><p> return false;<br /> }</p> ]]></content:encoded> </item> <item><title>By: Matt</title><link>http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/comment-page-1/#comment-12526</link> <dc:creator>Matt</dc:creator> <pubDate>Thu, 28 Jul 2011 14:10:14 +0000</pubDate> <guid isPermaLink="false">http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/#comment-12526</guid> <description>Thanks for the code!  However, when I try and copy and paste the code from the entry, it all ends up on one long line when pasted, rendering it useless.  Is there a way to copy and paste it so that it ends up on multiple lines like it appears here?Sometimes things that you wish were simple just aren’t :D</description> <content:encoded><![CDATA[<p>Thanks for the code!  However, when I try and copy and paste the code from the entry, it all ends up on one long line when pasted, rendering it useless.  Is there a way to copy and paste it so that it ends up on multiple lines like it appears here?</p><p>Sometimes things that you wish were simple just aren’t :D</p> ]]></content:encoded> </item> <item><title>By: Alex</title><link>http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/comment-page-1/#comment-12441</link> <dc:creator>Alex</dc:creator> <pubDate>Fri, 13 May 2011 15:50:05 +0000</pubDate> <guid isPermaLink="false">http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/#comment-12441</guid> <description>Thanks. Helped a lot! Alex.</description> <content:encoded><![CDATA[<p>Thanks. Helped a lot!<br /> Alex.</p> ]]></content:encoded> </item> <item><title>By: Anuj Pratap Singh</title><link>http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/comment-page-1/#comment-12028</link> <dc:creator>Anuj Pratap Singh</dc:creator> <pubDate>Fri, 10 Sep 2010 14:17:45 +0000</pubDate> <guid isPermaLink="false">http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/#comment-12028</guid> <description>Your blog helped me alot. Thanx alot.</description> <content:encoded><![CDATA[<p>Your blog helped me alot. Thanx alot.</p> ]]></content:encoded> </item> <item><title>By: akjoshi</title><link>http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/comment-page-1/#comment-12027</link> <dc:creator>akjoshi</dc:creator> <pubDate>Fri, 06 Aug 2010 07:40:27 +0000</pubDate> <guid isPermaLink="false">http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/#comment-12027</guid> <description>I have been trying to implement htis feature with virtualization enabled from past few days but no success, can you give any idea on how to do that?</description> <content:encoded><![CDATA[<p>I have been trying to implement htis feature with virtualization enabled from past few days but no success, can you give any idea on how to do that?</p> ]]></content:encoded> </item> <item><title>By: Alexandr</title><link>http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/comment-page-1/#comment-12026</link> <dc:creator>Alexandr</dc:creator> <pubDate>Fri, 30 Jul 2010 13:33:42 +0000</pubDate> <guid isPermaLink="false">http://quickduck.com/blog/2008/12/11/selecting-an-item-in-a-treeview-in-wpf/#comment-12026</guid> <description>Thanx a lot for this nice code!</description> <content:encoded><![CDATA[<p>Thanx a lot for this nice code!</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: quickduck.com @ 2012-02-08 15:34:38 -->
