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

10 posts, 0 answers
  1. saurabh
    saurabh avatar
    32 posts
    Member since:
    Jul 2010

    Posted 17 Nov 2010 Link to this post


    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
  2. Tsvyatko
    Admin
    Tsvyatko avatar
    833 posts

    Posted 17 Nov 2010 Link to this post

    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>>
  3. DevCraft banner
  4. saurabh
    saurabh avatar
    32 posts
    Member since:
    Jul 2010

    Posted 17 Nov 2010 Link to this post

    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
  5. Tsvyatko
    Admin
    Tsvyatko avatar
    833 posts

    Posted 17 Nov 2010 Link to this post

    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>>
  6. saurabh
    saurabh avatar
    32 posts
    Member since:
    Jul 2010

    Posted 17 Nov 2010 Link to this post

    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?
  7. jnh999
    jnh999 avatar
    29 posts
    Member since:
    Apr 2010

    Posted 06 Dec 2010 Link to this post

    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.
  8. jnh999
    jnh999 avatar
    29 posts
    Member since:
    Apr 2010

    Posted 06 Dec 2010 Link to this post

    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.
  9. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 09 Dec 2010 Link to this post

    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
  10. jnh999
    jnh999 avatar
    29 posts
    Member since:
    Apr 2010

    Posted 09 Dec 2010 Link to this post

    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.

  11. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 10 Dec 2010 Link to this post

    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
Back to Top
DevCraft banner