RadTreeView - prevent certain drops

2 posts, 0 answers
  1. Tomas
    Tomas avatar
    1 posts
    Member since:
    Aug 2016

    Posted 17 Aug Link to this post

    Hello,

    I am using RadTreeView and it's bind to an object (basically like in RadTreeView - Binding to object) with IsDragDropEnabled set to True. I use the following piece of code in XAML to define a structure

    <Window.Resources>
        <sampleData:RadTreeViewSampleData x:Key="DataSource"/>
        <DataTemplate x:Key="Team">
            <TextBlock Text="{Binding Name}" />
        </DataTemplate>   
        <HierarchicalDataTemplate x:Key="Division" ItemTemplate="{StaticResource Team}"
               ItemsSource="{Binding Teams}">
            <TextBlock Text="{Binding Name}" />
        </HierarchicalDataTemplate>
        <HierarchicalDataTemplate x:Key="League" ItemTemplate="{StaticResource Division}"
               ItemsSource="{Binding Divisions}">
            <TextBlock Text="{Binding Name}" />
        </HierarchicalDataTemplate>
    </Window.Resources>

     

    I need to support

    1. reordering groups (reordering divisions),
    2. items in group (swapping Team I and Team II)  and
    3. moving the items from one group to another (moving Team II to Division B).

    That is built-in and it works. I face other problems: 

    1. control allows nesting groups - if user drags Division B and puts it on Division A, Division B disappears. 
    2. the similar problem happens also with the lowest level (teams) 

     

    Hopefully the description is clear enough. Thanks for your time and help.

     

    Regards,

    Tomas

  2. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 19 Aug Link to this post

    Hello Tom,

    You can't nest divisions, leagues or teams because, the type of the children collection of the drop target node doesn't match the type of the dragged node. To make it clear, lets take the Division object for example. It have a children collection of type Team. When you drag another Division object and try to drop it in the Division under the mouse, the treeview cannot find a children collection of type (Division) and the drop operation fails.

    In order to achieve your requirement you can create a base class and base each node type on it. Then in each node class add a collection of the base class.

    However, using this approach you will need to change the data templating approach. Now you will need to use implicit templates or a data template selector. You can see this demonstrated in the attached project. Additionally, you can take a look at the Drag and Drop help article and section in the RadTreeView help documentation.

    Regards,
    Martin
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top