TargetDropItem is null

2 posts, 0 answers
  1. Nigel Shaw
    Nigel Shaw avatar
    4 posts
    Member since:
    Sep 2005

    Posted 04 Mar 2010 Link to this post

    I'm trying to get the underlying object (in this case a Model.Topic) for the e.TargetDropItem of a drag drop operation.

     

    private void RadTreeView_DragEnded(object sender, Telerik.Windows.Controls.RadTreeViewDragEndedEventArgs e)  
            {  
                object droppedTopics = e.DraggedItems;  
                  
                object targetDropItem = e.TargetDropItem;  
                Model.Topic targetTopic = targetDropItem as Model.Topic;  
     
                foreach (object droppedTopic in e.DraggedItems as Collection<object>)  
                {  
                    Model.Topic sourceTopic = droppedTopic as Model.Topic;  
                    targetTopic.ParentTopicId = sourceTopic.ID;  
                }  
            }  
     

    The problem is that after the line...

    Model.Topic targetTopic = targetDropItem as Model.Topic; 

    ... targetTopic is null.

    How can I get the actual object bound to the node that was the target of the drop?

    I posted this in the wrong forum. It should be in the WPF forum.

     

  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3299 posts

    Posted 10 Mar 2010 Link to this post

    Hello Nigel Shaw,

    The targetTopic is null because e.TargetDropItem is the dynamically generated container for your business object. Therefore you need to cast it to the type of the container (RadTreeViewItem) like this:
         RadTreeViewItem container = e.TargetDropItem as RadTreeViewItem;
    Afterwards, you can access the business object itself via the container.Item property:
        Model.Topic targetTopic = container.Item as Model.Topic;

    Best wishes,
    Tina Stancheva
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top