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

Drag drop between telerik treeview & silverlight listbox on silverlight child window

9 Answers 171 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
saurabh
Top achievements
Rank 1
saurabh asked on 17 Nov 2010, 12:01 PM

Hi,

I want drag drop between telerik treeview & silverlight listbox on silverlight child window.
For child window, we need to add controls in visual roots in drag query event as given below -
if (e.Options.ParticipatingVisualRoots.Contains(this) == false)
                e.Options.ParticipatingVisualRoots.Add(this);

I have done for listbox, but what addition need to do for treeview?

I want to drag item from tree & drop it on listview.

Thanks & regards,
Saurabh

9 Answers, 1 is accepted

Sort by
0
Tsvyatko
Telerik team
answered on 17 Nov 2010, 01:16 PM
Hi saurabh,

This code is required every time the drag is performed and child window participate in the drag (contains the source or the destination) and does not depends on the type of the source control.

if (!e.Options.ParticipatingVisualRoots.Contains(this))
e.Options.ParticipatingVisualRoots.Add(this);

where "this" is the ChildWindow instance.

All the best,
Tsvyatko
the Telerik team
See What's New in RadControls for Silverlight in Q3 2010 on Tuesday, November 16, 2010 11:00 AM - 12:00 PM EST or 10:00 PM - 11:00 PM EST: Register here>>
0
saurabh
Top achievements
Rank 1
answered on 17 Nov 2010, 01:44 PM
Thanks for reply.

It works fine if listbox is dragging control.

But for treeview, Drag Query event is not added on code behind. Only IsDragDropEnabled is set to true.
What should i do to for treeview drag query event?

Provide needful suggestion.

Thanks,
Saurabh
0
Tsvyatko
Telerik team
answered on 17 Nov 2010, 02:27 PM
Hi saurabh,

To make it work you need to attach to treeview dragQuery event using the following code:

RadDragAndDropManager.AddDragQueryHandler(MyTreeView, OnDragQuery); 
        
...
  
public void OnDragQuery(object sender, DragDropQueryEventArgs args) 
      
            
if (!e.Options.ParticipatingVisualRoots.Contains(this)) 
e.Options.ParticipatingVisualRoots.Add(this); 
  
      }


Let me know if you have any further issues.

Sincerely yours,
Tsvyatko
the Telerik team
See What's New in RadControls for Silverlight in Q3 2010 on Tuesday, November 16, 2010 11:00 AM - 12:00 PM EST or 10:00 PM - 11:00 PM EST: Register here>>
0
saurabh
Top achievements
Rank 1
answered on 17 Nov 2010, 02:58 PM
I have tried to add event using RadDragAndDropManager.AddDragQueryHandler for treeview,
but it is not getting fired at runtime.

Alternately i had tried to add through xaml

<telerik:RadTreeView Name="trvItems" IsDragTooltipEnabled="False"  IsDragDropEnabled="True" IsEditable="False" dragDrop:RadDragAndDropManager.DragQuery="OnDragQuery"  ></telerik:RadTreeView>

But then it is giving compile time error-

Error 1 The property 'DragQuery' does not exist on the type 'RadTreeView' in the XML namespace 'clr-namespace:Telerik.Windows.Controls.DragDrop;assembly=Telerik.Windows.Controls'.  
Can you provide sample example?
0
jnh999
Top achievements
Rank 1
answered on 06 Dec 2010, 04:23 PM
I have the same issue.  In the main UI window, there is a context menu.  When an item in the context menu is invoked, a child window (a RadWindow) shows up.  The child window contains two user controls.  On the left of the child window is a RadTreeListView and on the right is a RadTreeView.  I put the code 

      if (!e.Options.ParticipatingVisualRoots.Contains(this))
            {
                e.Options.ParticipatingVisualRoots.Add(this);
            }
 in the TreeListView DragQueryEvent handler, but the target (the RadTreeView) dropQuery or dropInfo handler never got invoked.  I am wondering what other wirings I need to put in to make this working.  Thanks for any help on this.
0
jnh999
Top achievements
Rank 1
answered on 06 Dec 2010, 10:15 PM
Actually, it is working now.  It is something else in the code prevented it from working.  I have two other questions though. 

1) Since I am drag and drop between a TreeListView to a TreeView and the node (the data) on them are different.  I need to do a conversion of the node data in the code before I can drop the node.  Where, i.e. which event handler should I use to do the data conversion before drop complete?

2)  If I don't implement the DropInfo event handler, the RadTreeView drag and drop manager automatically put the new entry in the right place in the tree.  Since I am implementing DropInfo event handler for the treeview (destination control), how do I know (programmatically) which node is my new node's parent?

Thanks.
0
Hristo
Telerik team
answered on 09 Dec 2010, 04:46 PM
Hello jnh999,

RadTreeView handles the DropQuery and DragQuery events of the RadDragAndDropManager. However DropInfo and DragInfo are not handled and propagate freely. You can either attach a handler to "Info" events like this:
RadDragAndDropManager.AddDropInfoHandler(RadTreeView1, new System.EventHandler<DragDropEventArgs>(OnDropInfo));

Or you could add handler to the "Query" events with handeledEvents=true like this:
RadTreeView1.AddHandler(RadDragAndDropManager.DropQueryEvent, new System.EventHandler<DragDropQueryEventArgs>(OnDropQuery), true);

I would like to recommend you to use some base class in both trees and change the data type. However, you can change the Payload property of the event args in DropQuery event for example. But in this case the originally dragged item will not be removed from the source tree.

In DragInfo event the "DragDropEventArgs.Options.Destination" hold a reference to the destination item. And the DropPosition property of RadTreeViewItem shows you where the node will be dropped (before, after or in).

Greetings,
Hristo
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
jnh999
Top achievements
Rank 1
answered on 09 Dec 2010, 07:49 PM
MyTreeView.AddHandler(RadDragAndDropManager.DragQueryEvent, new System.EventHandler<DragDropQueryEventArgs>(OnDropQuery), true);
  
private void OnDropQuery(object sender, DragDropQueryEventArgs e)
{
}

The first line does not compile.  It complaints about argument 1... cannot convert from Telerik.Windows.RoutedEvent to System.Windows.RoutedEvent.

0
Hristo
Telerik team
answered on 10 Dec 2010, 10:05 AM
Hi jnh999,

You should use the Telerik extension method AddHandler. It is located in Telerik.Windows namespace.

All the best,
Hristo
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
DragAndDrop
Asked by
saurabh
Top achievements
Rank 1
Answers by
Tsvyatko
Telerik team
saurabh
Top achievements
Rank 1
jnh999
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or