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

Checking node type before dropping

2 Answers 101 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, 10:52 PM
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 Answers, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 09 Dec 2009, 01:23 PM
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.
0
Lauren Nickerson
Top achievements
Rank 1
answered on 16 Dec 2009, 09:14 PM
Thanks much. I haven't found the time to test this yet, but I'll get back to you as soon as I do.
Tags
TreeView
Asked by
Lauren Nickerson
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Lauren Nickerson
Top achievements
Rank 1
Share this question
or