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

TreeView calls CollecectionChanged event on Drag&Drop

5 Answers 84 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Lauren Nickerson
Top achievements
Rank 1
Lauren Nickerson asked on 04 Dec 2009, 07:28 PM
So the structure of my tree is something like:

RootObject
    ChildObject1
        GrandChildObject1
    ChildObject2
        GrandChildObject2

Problem 1: When I drag and drop GrandChildObject1 to ChildObject2, the collection in ChildObject1 calls its Delete method, and I don't want that, since there's a few steps I need to do before removing GrandChildObject1 from ChildObject1.

Problem 2: When I drop GrandChildObject1 into ChildObject2, there's a few steps I need to do before finally adding GrandChildObject1 to ChildObject2. So doing this, also triggers the Add Method, so I end up having two children of the same item (one added by the TreeView itself, and one I add with my own method in the TreeView.RadTreeView_DragEnded event).

So, is there a way to prevent the TreeView from handling this, and not losing the little Drag&Drop preview when the drag starts? I just want to disable the TreeView from triggering a change in the Collection. I found out it was doing it by setting a breakpoint here:

private void GrandChildren_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) 
    this.NotifyPropertyChanged("GrandChildren"); // breakpoint here

EDIT: The collection of GrandChildren is an ObservableCollection<T>, and I can't change that to BindingList<T> or List<T>

Thanks!

5 Answers, 1 is accepted

Sort by
0
Accepted
Miroslav
Telerik team
answered on 04 Dec 2009, 08:11 PM
Hi Lauren Nickerson,

Yes, you can handle the PreviewDragEnded event (set e.Handled  = true for its event args) and this will mean that the TreeView will not modify its collections.

Then you can move your logic from the DragEnded to the PreviewDragEnded event because the former will not be called.

Hopefully this will work for you,

Best wishes,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Lauren Nickerson
Top achievements
Rank 1
answered on 06 Apr 2010, 09:57 PM
Is there another way to prevent this? I need DragEnded to fire, and setting e.Handled = true in PreviewDragEnded prevents it from doing so.

Lmk, thanks!
0
Valentin.Stoychev
Telerik team
answered on 07 Apr 2010, 06:38 AM
Hello Lauren Nickerson,

This is the idea of making e.Handled=true. When you do this the DragEnded event will not be raised. Why you need this event to raise? You can move your logic into the PreviewDragEnded event.

Greetings,
Valentin.Stoychev
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.
0
Lauren Nickerson
Top achievements
Rank 1
answered on 07 Apr 2010, 09:58 PM
Because at the time the PreviewDragEnded, the tree hasn't been updated with the new position of the items, and I need to get the new position of the drag item to do some operations. What other options do I have for this? I need a notification exactly after the Drag ends and the dropped item is showing its new position in the tree, so I can get the correct coordinate of said item within the tree.

Thanks.
0
Valentin.Stoychev
Telerik team
answered on 08 Apr 2010, 09:21 AM
Hello Lauren Nickerson,

If you handle the PreviewDragEnd event the node will not be moved at all. You need to do this manualy. You can execute the logic before the collection is updated and then to add the node in the correct position of the tree.

Regards,
Valentin.Stoychev
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
Lauren Nickerson
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Lauren Nickerson
Top achievements
Rank 1
Valentin.Stoychev
Telerik team
Share this question
or