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

Drag between TreeListView and TreeView

5 Answers 115 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Justin Lee
Top achievements
Rank 1
Justin Lee asked on 01 Apr 2013, 02:09 PM
I have a page were I drag from a TreeListView into a TreeView.  Both controls are bound to lists of the same item type.  I was using RadDragAndDropManager to wire up a couple events, which basically just QueryResult and IsDropPossible to true.  That was basically all I had to do to make the drag/drop work.   I recently upgraded to Q1 2013, and it stopped working.  I noticed RadDragAndDropManager was depreciated.  I'm trying to make this scenario work with DragDropManager, but I can't seem to figure out a simple solution.

- Drag from RadTreeListView to RadTreeView.  (only 1 way)
- Itemsources are of same object type.
- On TreeListView, I have set IsDragDropEnabled=True, AllDrop=False
- On TreeView, I have set IsDragDropEnabled=True, AllowDrop=True

I can drag between the TreeViews, but I cannot drop from the TreeListView on the TreeView.  (it drags, but doesn't drop)
(I have multiple treeviews, that can be dragged onto, but only on TreeListView (the source))

Thanks,
Justin

5 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 02 Apr 2013, 02:25 PM
Hi Justin,

You can subscribe to the DragOver event of the TreeList and set the e.Effects to None. 

Let me know if this helps! 

Regards,
Nik
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Justin Lee
Top achievements
Rank 1
answered on 04 Apr 2013, 09:10 PM
No, that did nothing.  I also tried the same thing with the TreeView, and also tried other effects (copy, move)

The treeview does not react to the drag, and when I drop, it does nothing.
private void RadTreeView_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
  RadTreeListView treeListView = (RadTreeListView)sender;
  DragDropManager.AddDragOverHandler(treeView, treeView_DragOver);
}
void treeView_DragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
{
  e.Effects = DragDropEffects.None;
}
0
Justin Lee
Top achievements
Rank 1
answered on 04 Apr 2013, 09:39 PM
I have created a simple project demonstrating the behavior (or lack of behavior)
<UserControl x:Class="DragExample.MainPage"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="600">
    <UserControl.Resources>
        <telerik:HierarchicalDataTemplate x:Key="TreeViewItemTemplate"
                 ItemsSource="{Binding ChildItems}">
            <TextBlock Text="{Binding Name}" FontSize="9"></TextBlock>
        </telerik:HierarchicalDataTemplate>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White"
              VerticalAlignment="Center" HorizontalAlignment="Center"
              Width="600" Height="300">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <telerik:RadTreeListView Loaded="RadTreeListView_Loaded_1" 
                Grid.Row="1" HorizontalAlignment="Stretch"
                IsDragDropEnabled="True"
                AllowDrop="False"
                AutoGenerateColumns="False" IsReadOnly="True"
                ShowGroupPanel="False" RowIndicatorVisibility="Collapsed"
                ItemsSource="{Binding TreeListItems}" SelectionMode="Single">
            <telerik:RadTreeListView.Columns>
                <telerik:GridViewDataColumn Header="Name" Width="180"
                          DataMemberBinding="{Binding Name}" />
                <telerik:GridViewDataColumn Header="Description" Width="*"
                          DataMemberBinding="{Binding Description}" />
            </telerik:RadTreeListView.Columns>
        </telerik:RadTreeListView>
 
        <telerik:RadTreeView  Grid.Column="1" HorizontalAlignment="Left"
                Loaded="RadTreeView_Loaded_1"
                SelectionMode="Single" MinHeight="150"
                ItemsSource="{Binding TreeItems}"
                telerik:DragDropManager.AllowDrag="True"
                telerik:DragDropManager.AllowCapturedDrag="True"
                IsDragDropEnabled="True"
                AllowDrop="True"
                IsEditable="false"
                ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                ItemTemplate="{StaticResource TreeViewItemTemplate}" 
                VerticalAlignment="Top"
                IsLineEnabled="True" />
    </Grid>
</UserControl>


public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            this.DataContext = new DataSource();
        }
 
        private void RadTreeListView_Loaded_1(object sender, RoutedEventArgs e)
        {
            RadTreeListView treeListView = (RadTreeListView)sender;
            DragDropManager.AddDragOverHandler(treeListView, treeListView_DragOver);
        }
 
        void treeListView_DragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
        {
            e.Effects = DragDropEffects.None;
        }
 
        private void RadTreeView_Loaded_1(object sender, RoutedEventArgs e)
        {
 
        }
    }
 
    public class DataSource : BasePropertyNotifyClass
    {
        public ObservableCollection<Item> TreeListItems { get; set; }
        public ObservableCollection<Item> TreeItems { get; set; }
 
        public DataSource()
        {
            TreeListItems = new ObservableCollection<Item>();
            TreeListItems.Add(new Item()
                { Name = "Item 1", Description = "Some Description" });
            TreeListItems.Add(new Item()
                { Name = "Item 2", Description = "Some Description" });
            TreeListItems.Add(new Item()
                { Name = "Item 3", Description = "Some Description" });
 
            TreeItems = new ObservableCollection<Item>();
            TreeItems.Add(new Item()
                 { Name = "Item A", Description = "Some Description" });
            TreeItems.Add(new Item()
                 { Name = "Item B", Description = "Some Description" });
            TreeItems.Add(new Item()
                 { Name = "Item C", Description = "Some Description" });
        }
    }
 
    public class Item : BasePropertyNotifyClass
    {
        public string Name { get; set; }
        public string Description { get; set; }
        public ObservableCollection<Item> ChildItems { get; set; }
 
        public Item()
        {
            ChildItems = new ObservableCollection<Item>();
        }
 
        public override string ToString()
        {
            return Name;
        }
    }
 
    public class BasePropertyNotifyClass : INotifyPropertyChanged
    {
         #region INotifyProperyChanged Interface
        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(String propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
    }
0
Accepted
Nick
Telerik team
answered on 08 Apr 2013, 12:29 PM
Hello Justin,

I am attaching a modified version of your sample, where you can see how you can achieve your goal.
The approach is a combined version of the behaviors shown here and here.

Hope it helps! 

Regards,
Nik
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Justin Lee
Top achievements
Rank 1
answered on 08 Apr 2013, 03:24 PM
Thank you for your help. I'll see if I can work with this project.  One thing I noticed is there is no feedback from the treeview on where the drop will occur.  This makes it very difficult to drop in the correct place in the tree.  It seems like its fairly complicated to get this to work, whereas it work with little code with the RadDragandDropManager in previous releases.  I may consider just using a treeview with a custom template instead of a treelistview so its easier to work with.  I appreciate your help though.

Thanks,
Justin
Tags
DragAndDrop
Asked by
Justin Lee
Top achievements
Rank 1
Answers by
Nick
Telerik team
Justin Lee
Top achievements
Rank 1
Share this question
or