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

wrong source&destination items with TreeView

1 Answer 35 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Adrien
Top achievements
Rank 1
Adrien asked on 18 May 2009, 11:38 AM
I want to drag & drop between two treeviews, but I rarely have the items I want. Often the source (e.Options.Source) is the root item of my treeview or sometimes the parent item of the item wanted. The same thing happens for the destination on drop.

Do you know what might cause the problem ?

Here is an example to reproduce the problem, with a visualization of the source item while dragging. When dragging

Page.xaml
<UserControl x:Class="SilverlightApplication1.Page"  
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"  
    xmlns:telerikDragDrop="clr-namespace:Telerik.Windows.Controls.DragDrop;assembly=Telerik.Windows.Controls" 
    Width="600" Height="400"
    <Grid x:Name="LayoutRoot" Background="White"
        <StackPanel Orientation="Horizontal"
            <telerikNavigation:RadTreeView x:Name="xTreeView" IsEditable="True"
                <telerikNavigation:RadTreeView.ItemContainerStyle> 
                    <Style TargetType="telerikNavigation:RadTreeViewItem"
                        <Setter Property="telerikDragDrop:RadDragAndDropManager.AllowDrag" Value="True" /> 
                        <Setter Property="telerikDragDrop:RadDragAndDropManager.AllowDrop" Value="True" /> 
                        <Setter Property="IsExpanded" Value="True" /> 
                    </Style> 
                </telerikNavigation:RadTreeView.ItemContainerStyle> 
                <telerikNavigation:RadTreeViewItem Header="Root"
                    <telerikNavigation:RadTreeViewItem Header="Folder"
                        <telerikNavigation:RadTreeViewItem Header="File" /> 
                        <telerikNavigation:RadTreeViewItem Header="File" /> 
                    </telerikNavigation:RadTreeViewItem> 
                </telerikNavigation:RadTreeViewItem> 
            </telerikNavigation:RadTreeView> 
        </StackPanel> 
    </Grid> 
</UserControl>  


Page.xaml.cs
using System; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Media; 
using Telerik.Windows; 
using Telerik.Windows.Controls; 
using Telerik.Windows.Controls.DragDrop; 
 
namespace SilverlightApplication1 
    public partial class Page : UserControl 
    { 
        public Page() 
        { 
            InitializeComponent(); 
 
            xTreeView.AddHandler(RadDragAndDropManager.DragQueryEvent, new EventHandler<DragDropQueryEventArgs>(OnTreeDragQuery), false); 
        } 
 
        private void OnTreeDragQuery(object sender, DragDropQueryEventArgs e) 
        { 
            RadTreeViewItem vControlItem = e.Options.Source as RadTreeViewItem; 
 
            if (e.Options.Status == DragStatus.DragQuery) 
            { 
                if (vControlItem != null
                { 
                    e.Options.ArrowCue = RadDragAndDropManager.GenerateArrowCue(); 
 
                    TextBlock vPreview = new TextBlock(); 
                    vPreview.Text = vControlItem.Header.ToString(); 
                    vPreview.Foreground = new SolidColorBrush(Colors.Blue); 
                    vPreview.FontWeight = FontWeights.Bold; 
                    vPreview.Opacity = 0.6; 
 
                    e.Options.Payload = vControlItem; 
 
                    e.Options.DragCue = vPreview; 
 
                    e.QueryResult = true
                    e.Handled = true
                } 
                else 
                { 
                    e.QueryResult = false
                    e.Handled = false
                } 
            } 
        } 
    } 
 

1 Answer, 1 is accepted

Sort by
0
Accepted
Miroslav
Telerik team
answered on 19 May 2009, 10:53 AM
Hello Adrien,

I confirmed that this is indeed the case. The bug is now fixed and will finds its way in the next Latest Internal Buid and consecutive releases (you should have the update by the end of this week).

As a temporary workaround, I can suggest to use the SelectedItems of the TreeView and assign them as a Payload.

Thank you for your feedback, your Telerik Points have been updated.

Best wishes,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
DragAndDrop
Asked by
Adrien
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Share this question
or