Prevent selected item on child nodes

3 posts, 1 answers
  1. Stefania
    Stefania avatar
    107 posts
    Member since:
    May 2013

    Posted 28 Jul 2015 Link to this post

    Hi,

    How can I prevent selected items on treelistview child nodes?

     

    Thank you

  2. Answer
    Stefan X1
    Admin
    Stefan X1 avatar
    523 posts

    Posted 30 Jul 2015 Link to this post

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

    Posted 30 Jul 2015 Link to this post

    Thank you!

    That's exactly what I'm looking for.

Back to Top