WPF TreeView Cancel TreeViewItem Selection
I've been looking for a solution to this problem but I still can't find an adequate solution yet. Please help. Basically, I have a treeview that's bound to a list of objects. 开发者_如何学运维When the user clicks on a treeviewitem, I load data for a data grid based on the treeviewitem. The user can change data in the grid. If there's a change in the data grid and the user clicks on another treeviewitem, the user is asked to save. The user can choose Yes, No, or Cancel. When the user chooses cancel, the application has to make the user stay on the current treeviewitem until he/she saves the data grid. The problem is once the user has selected another treeviewitem, I can't make it so that the previous selection is selected again. There is no "SelectedItemChanging" event. WPF treeview only has SelectedItemChanged event. I'm trying multiple solutions but I always end up with an infinitely. Please offer any tips or advices.
Thanks, Minh
You could just use a private field in which you store the item which was selected last, just handle the SelectedItemChanged event and always update the field as required. Also as Dave Clemmer suggested having an IsSelected
property to which you can bind helps with selecting items programatically.
精彩评论