DropQuery not being fired anymore (TreeViewItem)

5 posts, 0 answers
  1. Doug
    Doug avatar
    19 posts
    Member since:
    Jun 2010

    Posted 24 Jan 2012 Link to this post

    Hello, I've been using 2011 Q2 09.20 hotfix version of radcontrols for silverlight.  I'd like to upgrade but have been unable to do so because of issues with drag/drop with all versions released since.

    I have a radtreeview that I want to allow dropping items from different sources onto specific tree items.  As I mentioned this works fine in 2011 Q2 09.20 but not in later versions.  The problem with the later versions appears to be that the DropQuery event is fired for the treeview, but not for the specific treeviewitems.  Below is my code:
    XAML:
    <telerik:RadTreeView x:Name="rtvTags"
                         Grid.Row="1"
                         ItemTemplateSelector="{StaticResource TagTemplateSelector}"
                         ItemsSource="{Binding Items}"
                         PreviewExpanded="rtvTags_PreviewExpanded"
                         ScrollViewer.VerticalScrollBarVisibility="Auto"
                         ScrollViewer.HorizontalScrollBarVisibility="Auto"
                         AllowDrop="True"
                         telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}"
                         IsVirtualizing="True">

    Code behind:
       public partial class DocumentTagsView : ReviewView
        {
            public DocumentTagsView()
            {
     
                InitializeComponent();
                 
                RadDragAndDropManager.AddDropInfoHandler(rtvTags, Tags_DropInfo);
                RadDragAndDropManager.AddDropQueryHandler(rtvTags, Tags_DropQuery);
                rtvTags.MouseLeave += (s, ea) =>
                    {
                        ViewModel.ResetIsDropTarget();
                    };
     
            }
            private void Tags_DropQuery(object sender, DragDropQueryEventArgs e)
            {
                e.QueryResult = false;
                ViewModel.ResetIsDropTarget();
                if (e.Options.Payload is IList<IDSDocument> |
                    e.Options.Payload is IList<IDSSearch> |
                    e.Options.Payload is IList<SavedSearchItem>)
                {
                    DocTagItem item = e.Options.Destination.DataContext as DocTagItem;
                    if (item != null)
                    {
                        e.QueryResult = item.CanBulkTag;
                        item.IsDropTarget = true;
                        e.Handled = true;
                    }               
                }       
            }
    }

    Thanks

    Doug
  2. Nick
    Admin
    Nick avatar
    593 posts

    Posted 26 Jan 2012 Link to this post

    Hello Doug,

    Have you tried setting the TreeViews property IsDragDropEnabled to true?
    The reason that this is occurring is that the TreeView is using the DragQuery handler, for the internal use of the RadDragAndDropManager. 
    This change has been introduced because of our new DragDrop mechanism. The DragDropManager, which provides more intuitive API and allows the developer to create more complex drag and drop scenarios. You can read more about it here.

    Hope this helps!

    Regards,
    Nik
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Doug
    Doug avatar
    19 posts
    Member since:
    Jun 2010

    Posted 27 Jan 2012 Link to this post

    Thanks for the response.  I do not want to set IsDragDropEnabled to true because then the built in treeview drag/drop logic is used. 

    In this scenario I am not actually adding items to the tree view -  I am performing actions based on which item it is dropped onto.  Also whether or not a drop is allowed depends on the specific item it is dragged over.  From the code (again):

    DocTagItem item = e.Options.Destination.DataContext as DocTagItem;
    if (item != null)
    {
    e.QueryResult = item.CanBulkTag;
    item.IsDropTarget = true;
    e.Handled = true;
    }

    The property CanBulkTag tells it whether a drop can happen on a specific item.  IsDropTarget is a property I use to add a border around the item to indicate it's the drop target.  Attached is a screenshot of how it works (correctly) in 2011 Q2 09.20 release. 

    As I said in releases since then the DropQuery doesn't get called for specific items of the tree, only for the tree itself.  it is the first 2 lines of code that I can tell that from, in the later versions the criteria for the if statement is never met because e.Options.Destination is never a treeviewitem.

    I saw and read and tried using the new DragDrop framework without any luck.  I am having a hard time finding the equivalents in the new framework and there's currently not much sample code.  The new framework isn't the issue though (I don't think), as it was already available in 2011 Q2 09.20 version. 

    Thanks

    Doug

  5. Nick
    Admin
    Nick avatar
    593 posts

    Posted 31 Jan 2012 Link to this post

    Hello Doug,

    Unfortunately, the only other workaround that we can propose would be to subscribe to the ItemPrepared event, and set the AllowDrag property there. 
    private void TreeViewItemPrepared(object sender, RadTreeViewItemPreparedEventArgs e)
            {
                RadDragAndDropManager.SetAllowDrag(e.PreparedItem, true);
            }

    Hope this helps! 

    All the best,
    Nik
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. Doug
    Doug avatar
    19 posts
    Member since:
    Jun 2010

    Posted 02 Feb 2012 Link to this post

    Thanks, it does seem to work now (though it was SetAllowDrop that I had to call in the ItemPrepared event). 

    Doug
Back to Top
DevCraft banner