TreeView calls CollecectionChanged event on Drag&Drop

6 posts, 1 answers
  1. Lauren Nickerson
    Lauren Nickerson avatar
    52 posts
    Member since:
    Jul 2009

    Posted 04 Dec 2009 Link to this post

    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!
  2. Answer
    Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 04 Dec 2009 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Lauren Nickerson
    Lauren Nickerson avatar
    52 posts
    Member since:
    Jul 2009

    Posted 06 Apr 2010 Link to this post

    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!
  5. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 07 Apr 2010 Link to this post

    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.
  6. Lauren Nickerson
    Lauren Nickerson avatar
    52 posts
    Member since:
    Jul 2009

    Posted 07 Apr 2010 Link to this post

    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.
  7. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 08 Apr 2010 Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready