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

TargetDropItem is null

1 Answer 45 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Nigel Shaw
Top achievements
Rank 1
Nigel Shaw asked on 05 Mar 2010, 04:27 AM
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.

 

1 Answer, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 10 Mar 2010, 01:58 PM
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.
Tags
TreeView
Asked by
Nigel Shaw
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or