Checking node type before dropping

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

    Posted 04 Dec 2009 Link to this post

    Hi, so I'm wondering how I can check for that and disable the drop under some circumstances. I've already tried all the drag and drop events that make sense to me in the TreeView (DragEnter, DragStarted DragOver, PreviewDragEnter, PreviewDragStarted, PreviewDragOver), so when I start dragging and I move the dragged object around, none of this events get fired. I also tried an approach with the RadDragAndDropManager here:


    But to my surprise, the OnDropInsideTreeViewDropQuery event never got fired. Am I missing something here?

    What I want to do is pretty simple. I have several types of objects in my treeview, say:

    Junkyards
        Junkyard 1
             Cars
                Toyota Corola
                Nissan Sentra
             Furniture
                Stove
                Desk
             Computers
                Dell Inspiron
                HP a2921
        Junkyard 2
             Cars
                Toyota Corola
                Nissan Sentra
             Furniture
                Stove
                Desk
             Computers
                Dell Inspiron
                HP a2921

    So if the user drags a car from Junkyard1 to Junkyard2 and hovers it over Computers, basically I wan't to show a NO cursor, but if he does drag it over the Cars node, then it should allow him to drop there. The Junkyards cannot be dragged, so I need to check if the user is trying to drag a Junkyard and not allow him to.

    Please keep in mind that I'm not doing the TreeView filling in code or XAML, the data is coming from an XML document, so I can't just go to each RadTreeViewItem and set the IsDropAllowedProperty to false, it has to be done programmatically through the events.

    Thanks!
  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 09 Dec 2009 Link to this post

    Hello Lauren,

    I have attached a sample project that demonstrates one possible solution to your scenario. For the sake of the example, I have made the code as explicit as possible, so further refactoring is recommended. Also, the example covers the case where you drag/drop cars only, but it can easily be extended to support computers and furniture as well. The key to supporting this scenario is listening for the DragQuery event of RadTreeView.

    I have attached my sample project for further reference. Have a look at it and let me know how this works for you. Also, if you find something unclear, I'd be glad to provide more explanation on the subject.


    Greetings,
    Kiril Stanoev
    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 16 Dec 2009 Link to this post

    Thanks much. I haven't found the time to test this yet, but I'll get back to you as soon as I do.
Back to Top