RadTreeViewItem Disabled but selectable

3 posts, 1 answers
  1. Joe
    Joe avatar
    31 posts
    Member since:
    Apr 2012

    Posted 26 Oct 2012 Link to this post

    I would like to make a radtreeviewitem non-selectable but still be able to expand/contract it if it has children.
    Is that possible?
  2. Answer
    Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1183 posts

    Posted 29 Oct 2012 Link to this post

    Hi Craig,

    Your goal can be achieved by marking our PreviewSelectionChanged event as Handled - this can be done with the following  code:

    private void xTreeView_PreviewSelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
    {
        e.Handled = true;
    }

    By doing so the inner logic of the RadTreeView will not change the selection to any of the children, because the event will be invoked every time you click on a RadTreeViewItem. This is why you have to implement custom filtering logic to stop the selection only on specific nodes.

    Please keep in mind that the focus of the items is not controlled by this event and you have to deal with it manually, because the clicked item is not going to be selected but it is going to be focused.

    Regards,
    Pavel R. Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Joe
    Joe avatar
    31 posts
    Member since:
    Apr 2012

    Posted 29 Oct 2012 Link to this post

    Thank you,
    Giving the focus back to the removed item was what I was missing.

    private void TreeViewPreviewSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var rtv = sender as RadTreeView;
        var orgPocoNew = e.AddedItems[0];
     
        if (e.RemovedItems.Count > 0)
        {
            if (!PermissionHelper.HasEditPermissionsToOrg(_calViewModel.UserPoco, orgPocoNew))
            {
                e.Handled = true;
                var orgPocoOld = e.RemovedItems[0];
                RadTreeViewItem treeViewItem = rtv.ContainerFromItemRecursive(orgPocoOld);
                treeViewItem.Focus();
            }
        }
    }
Back to Top