Reputation: 13092
I Have Treeview (shown as above) in my app, I have binded it with collection... now the problem is whenever I expand on Colorodo by default Aspen should get selected, means whenever I expand first item that Node should get selected..
Any Ideas/suggestion Please
Upvotes: 2
Views: 7015
Reputation: 20571
Unfortunately, as I'm sure you have discovered, is that you cannot set the treeViewInstance.SelectedItem
property as it's read-only.
From memory, each TreeViewItem
has a IsSelected
property that you can set. You try to listen for expand/collapse on the items and maybe set this property. Without trying this myself I don't know if it is a) a good solution b) if it would even works.
To get the TreeViewItem
that is the container for the item in collection use
treeViewInstance.ItemContainerGenerator.ContainerFromItem(yourDataItem) as TreeViewItem;
Another idea (the way I would do it) is to use a ListBox/ListView and fake the hierarchical view. The create a view model controller and item, wrap your data, and manage this all yourself. If you want more information, please leave a comment and I will dig up a few examples to help.
HTH,
Dennis
Upvotes: 6
Reputation: 21899
There are two apporches choose what ever you like. i) explore ItemTemplageSelector, not sure but may be possible to do work with it.
Other wise on tree expand event or mouse capture event get the Current Root node and then select its first child with index like rootNode.child[0]... set this is as Selected True or Isfocused and perfom operation that is intended on its click you you will make user feel like it is selected.
Upvotes: 0