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

RadTreeView - prevent certain drops

1 Answer 108 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Tomas
Top achievements
Rank 1
Tomas asked on 17 Aug 2016, 10:31 AM

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

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 19 Aug 2016, 10:13 AM
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.
Tags
TreeView
Asked by
Tomas
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or