6 Answers, 1 is accepted
0
Hello Tal,
You can use the PreviewSelected event to stop selection of an item. Check the code below:
Please let us know if you have any other questions!
Regards,
Boryana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
You can use the PreviewSelected event to stop selection of an item. Check the code below:
<telerik:RadTreeView |
x:Name="RadTreeView1" |
PreviewSelected="RadTreeView1_PreviewSelected"/> |
void private void RadTreeView1_PreviewSelected(object sender, RadRoutedEventArgs e) |
{ |
// get a reference to the item that will be selected |
RadTreeViewItem itemToSelect = e.Source as RadTreeViewItem; |
// if the action should be canceled set Handled property to true |
e.Handled = true; |
} |
Please let us know if you have any other questions!
Regards,
Boryana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Tal
Top achievements
Rank 1
answered on 17 Feb 2009, 06:10 PM
Hi,
well this way the Unselected event is still being thrown so my previous selection doesn't exist anymore. Anyway, I used the SelectionChanged event to validate and rollback in case the validation has failed.
Thanks,
Tal
well this way the Unselected event is still being thrown so my previous selection doesn't exist anymore. Anyway, I used the SelectionChanged event to validate and rollback in case the validation has failed.
Thanks,
Tal
0
Ogi Ivanov
Top achievements
Rank 1
answered on 23 Feb 2010, 03:32 PM
Hi Broyana,
I'm working on a WPF project using the MVVM pattern and I have two questions related to this post:
1. Can I stop the next selection of a tree item using the ViewModel instead of handling the event in the code behind.
2. How can I keep the selected brush on the previously selected item when the selection is stopped.
Thank you,
Ogi Ivanov
I'm working on a WPF project using the MVVM pattern and I have two questions related to this post:
1. Can I stop the next selection of a tree item using the ViewModel instead of handling the event in the code behind.
2. How can I keep the selected brush on the previously selected item when the selection is stopped.
Thank you,
Ogi Ivanov
0
Hello Ogi Ivanov,
1. Currently there is no way to stop the selection from the ViewModel. If you want to use databinding you may create a property in your view that will be databound to a property in your ViewModel that will specify whether the PreviewSelectionChanged event should be handled (this will stop the selection).
The above is also true if you make this into an attached property or behavior and attach it where you want the selection to be handled.
2. The item will be grayed-out if it is selected but the TreeView has no focus. Calling Focus() on the TreeView should keep it unchanged.
Alternatively if you want to have the same visual look but keep the focus away from the TreeView you will need to edit the TreeViewItem's template.
Sincerely yours,
Miroslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
1. Currently there is no way to stop the selection from the ViewModel. If you want to use databinding you may create a property in your view that will be databound to a property in your ViewModel that will specify whether the PreviewSelectionChanged event should be handled (this will stop the selection).
The above is also true if you make this into an attached property or behavior and attach it where you want the selection to be handled.
2. The item will be grayed-out if it is selected but the TreeView has no focus. Calling Focus() on the TreeView should keep it unchanged.
Alternatively if you want to have the same visual look but keep the focus away from the TreeView you will need to edit the TreeViewItem's template.
Sincerely yours,
Miroslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Robert
Top achievements
Rank 1
answered on 10 Apr 2013, 10:28 PM
I was looking for something very similar, but I needed to get the actual RadTreeViewItem, as your code example showed. However e.Source actually returns the TreeView, not the item being unselected, and as you try to cast it as a RadTreeViewItem the itemToSelect would actually be null. Is there a way to actually get the item being selected/unselected in the event?
0
Hello Robert,
We did some refactoring to the RadTreeView control since the time of the post (02.17.2009). However, you are allowed to access the selected RadTreeViewItem by using the e.OriginalSourceproperty. Please try it out and led us know if you have any other questions.
Kind regards,
Pavel R. Pavlov
the Telerik team
We did some refactoring to the RadTreeView control since the time of the post (02.17.2009). However, you are allowed to access the selected RadTreeViewItem by using the e.OriginalSourceproperty. Please try it out and led us know if you have any other questions.
Kind regards,
Pavel R. Pavlov
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.