WPF Set Selected Treeview item

OFGemini
OFGemini used Ask the Experts™
on
Hello,

In WPF, How do I set the Selected Treeview item and make it visible?

Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
There are some workarounds on the net around, including some really ugly ones (like loading the whole tree in background asyncronously and trying to display the derired node :) ), but the best one which I could find, is to create a viewmodel (see for MVVM pattern if interested), add an IsSelected property to it, and bind it to the IsSelected property of the related treenode.

Then you can simply select (or even expand) the related items via your viewmodel, which is pretty much under your control.

It sounds a bit complicated this way, but it is explained pretty well on Bea Stollnitz's blog:
http://bea.stollnitz.com/blog/?p=54
http://bea.stollnitz.com/blog/?p=55
http://bea.stollnitz.com/blog/?p=59

Regards,

Author

Commented:
I found the solution on my own.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial