Link to home
Start Free TrialLog in
Avatar of OFGemini
OFGemini

asked on

WPF Set Selected Treeview item

Hello,

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

Thanks.
Avatar of gyoreg
gyoreg
Flag of Hungary image

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,
ASKER CERTIFIED SOLUTION
Avatar of OFGemini
OFGemini

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of OFGemini
OFGemini

ASKER

I found the solution on my own.