DragDrop Payload

3 posts, 1 answers
  1. Gerrit Fölster
    Gerrit Fölster avatar
    6 posts
    Member since:
    Sep 2009

    Posted 23 Mar 2012 Link to this post

    Hi Telerik Team,

    I'm using a DropQuery handler on a my treeview:
    TreeViewControl.AddHandler(RadDragAndDropManager.DropQueryEvent, new EventHandler<DragDropQueryEventArgs>(OnDropInsideTreeViewDropQuery),true);

    private void OnDropInsideTreeViewDropQuery(object sender, DragDropQueryEventArgs e)
        List<MyEntity> draggedTasks = ((Collection<object>)e.Options.Payload).Cast<MyEntity>().ToList();
    Sometimes the e.Options.Payload contains a number of MyEntity items (as expected) and an additional item of type object which leads to an exception when calling .Cast<MyEntity>.

    The whole TreeView is databound via HierarchicalDataTemplate, IsSelected and IsExpanded are also bound via ContainerBindings. I'm dragging within the tree, no other controls are involved.

    I'm using Telerik 2011 Q3 on Silverlight 5.
    Unfortunately I'm not always able to reproduce this behavior. Can you give any hints on this issue?

  2. Answer
    Hristo avatar
    352 posts

    Posted 27 Mar 2012 Link to this post


    I've myself encountered similar situations (not in drag and drop scenario) when the related data item (RadTreeViewItem.Item) with the RadTreeViewItem container is just a object.

    This could happen when ItemContainerGenerator has generated a container for the data item but the container is not yet initialized correctly. These occasions are mainly related with the selection logic which makes me believe there is something wrong going inside the selection and related bindings.

    Could you try to simulate the issue when there are no bindings to the IsSelected property?

    Also, could you check if the count of dragged items is the correct one or there is one additional item?
    If the count is greater than the real dragged items count, I  would suggest you to just filter the collection.

    Hope this helps. I'm looking forward for your post on the topic.

    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. Gerrit Fölster
    Gerrit Fölster avatar
    6 posts
    Member since:
    Sep 2009

    Posted 02 Apr 2012 Link to this post

    Hello again,

    as you suggested, I removed the bindings to the IsSelected property and the problem no longer occurs.
    As a workaround I now handle SelectionChanged on the treeview and set the IsSelected property on my entities according to the AddItems and RemovedItems parameters.

    Thank you for pointing me in the right direction,
Back to Top