This is a migrated thread and some comments may be shown as answers.

RadTreeView selection

5 Answers 214 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Pelli
Top achievements
Rank 1
Pelli asked on 06 Jul 2015, 12:18 PM

Hi,

I have a RadTreeView with checkboxes(Implemented using MVVM as suggested by Telerik). To work with Keyboard events(checkbox should be checked when we enter a space), We implemented KeyDown event and is working fine.

Now if I select an item and enter space it gets checked, if I click on tab the next item gets focus but still the first item is in selected mode. Is there any way to get unselected, when we tab out . Please provide your inputs.

 

Thanks,

Subhashini

 

5 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 07 Jul 2015, 12:08 PM
Hi Pelli,

RadTreeViewItem is UIElement and therefore it has LostFocus routed event. For routed events you can subscribe witht he following syntax:
this.AddHandler(RadTreeViewItem.LostFocusEvent, new RoutedEventHandler(item_LostFocus), true);

In the handler you can decide whether to change the container properties directly or the ViewModel's properties:
void item_LostFocus(object sender, RoutedEventArgs e)
     {
         var container = e.OriginalSource as RadTreeViewItem;
         if (container != null)
         {
             var model = container.DataContext;
             //
             // code for setting model properties here.
             //
 
             // code setting properties of container below=>
             container.IsSelected = false;
         }
     }

We hope this fits well in your scenario.

Regards,
Petar Mladenov
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Pelli
Top achievements
Rank 1
answered on 07 Jul 2015, 01:27 PM
Yes it helps. Now, when i tab out from item1 to item2, item1 gets deselected. But I want item2 to get selected. How can we acheive this?
0
Petar Mladenov
Telerik team
answered on 09 Jul 2015, 10:41 AM
Hi Pelli,

Similarly to LostFocus, you can use GotFocus event and perform the selection logic in its handler. Hope this helps.

Regards,
Petar Mladenov
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Pelli
Top achievements
Rank 1
answered on 10 Jul 2015, 10:09 AM

Hi,

I have a treeview with checkboxes(Implemented using trivial state MVVM as suggested by Telerik). Now if I select radtreeview items with shift+down arrow(say five items are selected). When I click "space" key, only last selected item is checked. This is because the radtreeview.SelectedItems is giving only the last selected item. Is it a known issue?

If I do the same workflow with Shift+Space key, then all the selected items are checked. Can you provide inputs how can we acheive this functionality only with space key for all the selected items to get checked.

Thanks,

Subhashini

0
Petar Mladenov
Telerik team
answered on 14 Jul 2015, 12:11 PM
Hello Pelli,

In Extended SelectionMode, the SelectedItems collection will give you the collection of all selected Viewmodels in databound scenario. If you mean CheckedItems, please note that there are some known bugs with this collection and we highly encourage you to avoid using it.

In the attached solution you can find a possible approach for checking all selected items in code behind.
In PreviewKeyDown event you can iterate the selected models and set their property:
private void tree_PreviewKeyDown(object sender, KeyEventArgs e)
     {
         if (e.Key == Key.Space)
         {
             foreach (var item in this.tree.SelectedItems)
             {
                 (item as DataItem).IsChecked = true;
             }
             e.Handled = true;
         }
     }

The built-in logic for checking items with space will work only for not-databound trees and built-in checkboxes. Also it will only check the item which holds the keyboard focus.

Regards,
Petar Mladenov
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
TreeView
Asked by
Pelli
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Pelli
Top achievements
Rank 1
Share this question
or