RadTreeView selection

6 posts, 0 answers
  1. Pelli
    Pelli avatar
    11 posts
    Member since:
    May 2014

    Posted 06 Jul 2015 Link to this post

    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

     

  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 07 Jul 2015 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Pelli
    Pelli avatar
    11 posts
    Member since:
    May 2014

    Posted 07 Jul 2015 in reply to Petar Mladenov Link to this post

    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?
  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 09 Jul 2015 Link to this post

    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
  6. Pelli
    Pelli avatar
    11 posts
    Member since:
    May 2014

    Posted 10 Jul 2015 in reply to Petar Mladenov Link to this post

    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

  7. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 14 Jul 2015 Link to this post

    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
Back to Top
UI for WPF is Visual Studio 2017 Ready