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

[Solved] Drag & Drop issue with Hierarchical Data Template...

5 Answers 178 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Richard
Top achievements
Rank 1
Richard asked on 23 Sep 2009, 06:20 AM
Hi all,

I'm using the evaluation version of the controls, as I'm not currently satisfied with the ones that I have access to, and am not quite willing to fork over the cash until I can prove the scenarios that I need to prove for the project I'm on.

With that said, I wrote a simple interface with a RadGridView, a RadTreeView, and have enabled drag and drop on the TreeView (inherent version against the treeview) and also using the RadDragAndDropManager have added drag & drop functionality between the grid and the tree view.

I'm running into this flaky issue where I cannot seem to perform a "Drop" onto any of my last level nodes in the list... (for reference, I've got three levels).  I commented out my level 3 in the tree, and still ran into the issue (could not drop onto any level 2 objects).  I can, however drop before or after them.

What I'm wondering is if this is indeed supported, and if not, when is it going to be?  the three levels are inner-nesting buckets in my application, and the data from the grid can go into any of the buckets (think of using windows explorer here)...

Any assistance would be appreciated.

5 Answers, 1 is accepted

Sort by
0
Miroslav
Telerik team
answered on 25 Sep 2009, 04:45 PM
Hi Richard,

Yes, hopefully you will be able to test the controls in the scenarios you need them for.

Of course, dropping the into the last-level nodes should be supported. I modified an examples project, using the 2009.2 812 version of the assemblies and I could not reproduce the issue.

If you are suing DataBinding one reason for this behavior could be that the collection that is bound as an ItemsSource (described in the HierarchicalDataTemplate) has not been initialized for the last level items. In this case the TreeView will not create the collection itself. The solution is to always initialize the property that will provide the ItemsSource to an empty observable collection if it is not used.

Could you please share the code of your DragDrop handlers or a sample project where the issue is present?

Is the issue present with the assemblies form the Latest Internal Build?

I have attached my project to this reply,

Kind regards,
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
Richard
Top achievements
Rank 1
answered on 25 Sep 2009, 07:39 PM
Silverlight Example
(Unfortunately, you don't allow users to upload files on the forum, which is a shame... makes this painful for some of us.)

As you can see in the example, everything is being bound by an observable collection.  In the real-world usage of this, my hierarchy is a "Group" => "Department" => "Category", where "Group" and "Department" have a property of ObservableCollection<Department> or ObservableCollection<Category> called Children that I'm binding out to the HierarchicalDataTemplate.

I did download and see that you were working, and I will start digging into your code a bit to see what I misunderstood with mine that is causing the issue.  If you can shed light on this, that would be simply awesome.

I should add one more note of interest... that is the example of the treeview not being able to drop on the category.  I'm running into this same issue if I'm dragging from the grid to the treeview.  I re-read your post.  Am I to take it that having an empty ObservableCollection<object> on my Category class is the "only" answer?  I ask because it makes for bad design in the system, and I'm trying to keep the code so that an API can be written against/for it in the not too distant future.

Again... Thx for your help/assistance with this.
0
Miroslav
Telerik team
answered on 28 Sep 2009, 10:47 AM
Hi Richard,

Thank you for sending the project! 

Yes, unfortunately we do not yet allow attachments in the forums yet, you need to open a support ticket to add an attachment.

I had a look at your example and the children collection of the children was not initialized. I.e. the children were created like so:

v.Children.Add(new testvalues() { text = "Text"}); 

This means that the Children collection of these items will always be null. Thus the ItemsSource binding set in the HierarchicalDataTemplate will never assign an ItemsSource to the TreeViewItems. Then when the TreeView sees that there is no items source for the children, it will not allow dropping items there.

The fix in this case is to initialize the collection as well:

v.Children.Add(new testvalues() { text = "Text", Children = new ObservableCollection<testvalues>() }); 

I am sorry if I was not clear enough for the observable collection.

It is not needed to expose ObservableCollection as a type in your models. The type of the property can be anything that is at least IEnumerable. The object that is returned though is best to implement INotifyCollectionChanged, because this way the TreeView will get notifications when items are added/removed from the source collection. Currently the most used implementation of this is the ObservableCollection<>. Nothing stops you from typing your properties differently or returning another collection though.

I modified your example to use IEnumerable as type and I am attaching it here.

Hopefully this will work for you,

Kind regards,
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
Richard
Top achievements
Rank 1
answered on 28 Sep 2009, 11:08 AM
Miroslav:

If I change the way I am doing the drag & drop functionality to use the RadDragAndDropManager instead of using the inherent drag and drop functionality built into the RadTreeView, will this allow me to enable the drag and drop functionality that I wish to have?

What I'm trying to do is that in the 3rd level, the "categories" level, I don't want to drag groups or departments on it, and I even agree with the way the categories can only be dropped before/after another category (naturally)... but I want to be able to drag a product from the Products grid on the right-hand side of the screen, and drop it onto a group/department/category.  That's triggering a reclassification of the product into the new Group/Department/Category that the product is assigned to.  Is this possible to do "today"?
0
Miroslav
Telerik team
answered on 30 Sep 2009, 08:35 AM
Hi Richard,

Yes, you can achieve this today.

The TreeView internally uses the RadDragAndDropManager, so you will be able to tweak the TreeView DragDrop to your needs.

The best thing to do here is to handle the DropQuery event for the TreeView. There you have the item that is being dragged and where it is dropped and you can deny / approve a drop.

The DropInfo event can also be handled which will give the user feedback and will do the actual reclassification.

I modified my previous example so that dropping product in the TreeView will reclassify them. The example does not have the exact same structure you described, but it demonstrates the same scenario.

Since this is a larger example I marked the comments of interest with //RICHARD:

Hopefully this will help you,

Regards,
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.
Tags
TreeView
Asked by
Richard
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Richard
Top achievements
Rank 1
Share this question
or