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

Prevent selected item on child nodes

2 Answers 41 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Stefania
Top achievements
Rank 2
Stefania asked on 28 Jul 2015, 01:58 PM

Hi,

How can I prevent selected items on treelistview child nodes?

 

Thank you

2 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 30 Jul 2015, 01:19 PM
Hi Stefania,

The check for such restriction should be performed on data-level. You can subscribe to the SelectionChanging event of RadTreeListView. SelectionChangingEventArgs exposes a property, from which you can benefit: AddedItems. You can check if the child collection contains the currently selected item with logic similar to the one proposed below:
private void treeFileSystem_SelectionChanging(object sender,
    SelectionChangingEventArgs e)
{
    var selected = e.AddedItems[0] as Club;
 
    if (selected != null)
    {
        var clubs = (this.treeFileSystem.ItemsSource as ObservableCollection<Club>)
            .Where(c => c.NestedClubs.Contains(selected));
 
        if (clubs.Count() > 0)
        {
            e.Cancel = true;
        }
    }
}

Can you please give the approach a try and let me know should you need further assistance?

Best Regards,
Stefan
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
Stefania
Top achievements
Rank 2
answered on 30 Jul 2015, 02:29 PM

Thank you!

That's exactly what I'm looking for.

Tags
TreeListView
Asked by
Stefania
Top achievements
Rank 2
Answers by
Stefan
Telerik team
Stefania
Top achievements
Rank 2
Share this question
or