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

RadTreeViewItem Disabled but selectable

2 Answers 115 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Joe
Top achievements
Rank 1
Joe asked on 26 Oct 2012, 06:38 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Pavel R. Pavlov
Telerik team
answered on 29 Oct 2012, 08:50 AM
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.

0
Joe
Top achievements
Rank 1
answered on 29 Oct 2012, 02:29 PM
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();
        }
    }
}
Tags
TreeView
Asked by
Joe
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Joe
Top achievements
Rank 1
Share this question
or