Tree 1 (these items are static and cannot change. If you drag and drop, it copies the item instead of moving)
Say I drag 'Item 1' to add it to both 'Group A' and 'Group B'. So Tree 2 now looks like:
- Item 1
- Item 1
If I click to select 'Item 1' in 'Group B' it selects 'Item 1' in 'Group A'. It seems like when making a selection, it searches the tree from the top-down for the item that was clicked on and selects the first occurrence. So if I ever try to drag 'Item 1' from 'Group B' and move it to 'Group C', it will actually move 'Item 1' from 'Group A' to 'Group C'.
I apologize if that seems confusing, not sure if I can explain it any better though. It's a really strange behavior and I'm sure it is not intended; however, I may be doing something wrong as well. I created 'HierarchicalDataTemplate' and 'DataTemplate' to set how the data displays my view model. I am also using the 'new' DragDropManager as well. The version of components we are using is 2013.3.1316.45 (we decided to not renew the license so this is the latest version available to us).
Is there something I could be doing wrong? Is there a work around I could use?
Thanks for any help
5 Answers, 1 is accepted
Thank you for the explanation.
The reported behavior is caused by the fact that when you use the default drag and drop behavior of the RadTreeView and when you drag copy an item the tree won't create a new item but will add the same item at the drop position. Then when you select an item, the internal selection logic of the treeview will search for the selected item and if you have two (or more) items of the same instance, the tree will select the first found.
In order to avoid this behavior you can reconfigure the default drag and drop behavior of the RadTreeView to make a deep copy of the dragged item and drop the copy. You can take a look at the Copy Item When Dragging Within The Same Tree section from the Implement Copy Drag help article, which demonstrates such implementation. In addition I attached a sample project with a similar approach like in the article. Note that you will need to enable the drag drop of the tree views after attaching your drag/drop event handlers. Otherwise this approach won't work correctly.
Please let me know if this helps.
After looking at it some more, the issue isn't necessarily with my drag drop process. It's the actual selection of an item (when clicking on it). I'm loading the two trees from a view model that connects to my database (the particular part of the database I'm working with has a many-to-many relationship). So for example say we have the standard 'Products' table and a 'Orders' table, then the table in between for 'OrderProducts'. In my treeview I have the 'Orders' as the group and I want to list the products for each order. The problem is when you said:
"Then when you select an item, the internal selection logic of the treeview will search for the selected item and if you have two (or more) items of the same instance, the tree will select the first found."
So basically if I select a product from order/group 2, then it is going to select the same product from order/group 1 instead. You can see that's obviously not the desired behavior. I would understand if you are searching the entire tree for a specific object that it'd behave that way. But when I actually click on an item in group 2, why would it have to search the tree for the item I'm actually clicking on? And if for some reason it does have to search, wouldn't it be better to search the current parent group for the item I clicked instead of the entire tree?
I'm not real sure how to even tackle this. I'll post some code after while after I make some modifications. Thanks again.
And my data templates and tree definitions:
We have 'AvailableProducts' bound to one tree and 'OrderGroups' bound to another. Our particular issue is the 'OrderGroups' tree. Is there something I should be doing differently? Any help or direction you can provide would be great.
Note that when you click an item in order to select it, the selection logic of the tree will get the DataContext of the clicked item and traverse recursively the tree to find the RadTreeViewItem which has this DataContext, and then select the found item. This means that if you have two items of the same instance (they point to the same location in the memory) the item that is higher in the tree hierarchy will be selected. For example, if you have the following tree:
and click "Item 1.3" from the children of "Item 2" node, the "Item 1.3" from the children of "Item 1" node will be selected.
If you don't want this behavior to appear you will need to create a new instance for each business object from the tree's collection before you pass it to the tree. Here is an example code: