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

Binding to Self-Reference Hierarchy and Drag/Drop

9 Answers 293 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
TSRG - IT
Top achievements
Rank 1
TSRG - IT asked on 28 May 2010, 09:05 AM
Hi guys,

I've followed the self-reference hierarchy example and have implemented the custom DataItemCollection. The tree binds great and I am able to view all the tree items. However, now I want to have the drag/drop ability too, I've found that I can't "Drop-Inside" and also, when I can, drop before or after the program gives me the following exception:

NullReferenceException
at Telerik.Windows.Controls.RadTreeView.EndDrop(FrameworkElement dropTarget, IEnumerable draggedItemsEnumerable) in c:\\Builds\\WPF_Scrum\\Release_WPF\\Sources\\Development\\Controls\\Navigation\\TreeView\\RadTreeView.cs:line 2147\r\n   at Telerik.Windows.Controls.RadTreeView.OnDropComplete(FrameworkElement dropDestination, IEnumerable draggedItems) in etc...

I have pretty much following the example found in the documentation exactly and extended the ObservableCollection. I have only  enabled the property IsDragDropEnabled to true to turn on this feature. Is there something else I must do to make the dropping work?

Thank you,

Tim.

9 Answers, 1 is accepted

Sort by
0
Accepted
Tina Stancheva
Telerik team
answered on 02 Jun 2010, 04:09 PM
Hi Timothy Lin,

I attached a couple of projects demonstrating how you can use a HierarchyConverter that allows you to implement the drag and drop functionality that you are looking for. Please take a look at them and let me know if you need more info.

Kind regards,
Tina Stancheva
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.
0
Olivier
Top achievements
Rank 1
answered on 09 Nov 2010, 09:56 AM

Hi Tina,
First i want to say that I'm newbie in WPF!

I'm afraid I need a little bit more info ...
I have a self-referenced treeview with a simple converter like this example : http://www.telerik.com/help/wpf/radtreeview-how-to-bind-to-self-referencing-data.html
Can you tell me please how i can adapt this converter the more simply possible to make drag and drop working well ?
Thanks in advance.
Olivier.

0
Tina Stancheva
Telerik team
answered on 10 Nov 2010, 06:18 PM
Hi OLIVIER,

The help article describes a simplified approach for displaying a self-referencing hierarchy into the RadTreeView. However, when it comes to the drag and drop functionality of the RadTreeView, this example won't work. Let me try to explain why.

The drag/drop feature of the RadTreeView tries to reorder the RadTreeView underlying business collection. In cases when this collection isn't notified of the RadTreeView ItemsSource changes, no drag/drop can be implemented. Therefore it is very important to note that in order to drag/drop RadTreeViewItems, the business collection they represent should implement the INotifyPropertyChanged interface.
Another important note here, is that if you want to allow dropping onto a RadTreeViewItem, you have to make sure that the underlying data item has a property (a collection of items) where the dragged data item can be added.

Keeping these notes in mind, the article approach has to be slightly modified. I prepared a sample project illustrating a possible approach for that. I added a Children property in the DataItem class and a SetChildren class method. I also modified the HierarchyConverter class to populate each item's children collection accordingly to the ID references. Please have a look at the solution and let me know if it works for you or if you need more info.

Regards,
Tina Stancheva
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
0
Olivier
Top achievements
Rank 1
answered on 14 Nov 2010, 10:29 PM
Hi Tina,
it's just perfect, this sample helped me very much.
Thanks a lot !

If I can keep this thread on another problem about self-referenced treeview :
could you give please me some help to extend my sel_referenced treeview on another table so to obtain a treeview like this :

Parent element 1
    |--Children element 1.1
    |--Children element 1.2
        |-- Equipement A
        |-- Equipement B
Parent element 2
    |-- Equipement C
    |--Children element 2.1
         |-- Equipement D
    |--Children element 2.2
        
Two tables :
T_element with self-reference hierarchy (idElement, idElementParent) 
T_Equipement in association with T_element (idEquipement, idElement(fk))

and all of that with drag/drop ability of course ...

OLIVIER.
0
Selvakumar Savarimuthu
Top achievements
Rank 1
answered on 16 Nov 2010, 11:20 AM

Hi Tina,

 

Would you be able to guide me to achieve the drag and drop for self-referencing hierarchy in Silverlight 3?

 

Thanks,

Prasanna R

0
Tina Stancheva
Telerik team
answered on 17 Nov 2010, 04:35 PM
Hello OLIVIER,

In order to display multiple child types in the RadTreeViewItems hierarchy, you need to make sure that they inherit one common type. This will allow you to set one children collection for each DataItem and populate it with DataItems as well as Equipment items. Please note that you can only set one children collection as an ItemsSource in the HierarchicalDataTemplate for each RadTreeViewItem.

I modified the sample to illustrate a possible approach towards your scenario. Please have  a look at it and let me know if it works for you.

Greetings,
Tina Stancheva
the Telerik team
See What's New in RadControls for WPF in Q3 2010 on Tuesday, November 16, 2010 11:00 AM - 12:00 PM EST or 10:00 PM - 11:00 PM EST: Register here>>
0
Olivier
Top achievements
Rank 1
answered on 18 Nov 2010, 05:31 PM
Hi Tina,
this example set me on the right track and it works great for me, thanks a lot !!

Best regards
Olivier.
0
Prakash
Top achievements
Rank 1
answered on 02 May 2012, 08:12 AM
Hi Team,

I have requriement to have Self Reference Hierarchy Model in Treeview.
Solution which u have provided was great.

I have one more requirement.

Requirement #: Dynamically adding items after the Treeview has been loaded.

On a button click im adding a new item to a parent node, collection is getting changed but not the Treeview is getting updated.
i have attached a sample regarding my requirement. Could u please help me solve this.

private

 

 

void Button_Click(object sender, RoutedEventArgs e)

 

{

 

 

DataItemCollection ct = (DataItemCollection)this.DataContext;

 

ct.Add(

 

new DataItem() { Text = "Item 13.3", Id = 13, ParentId = 0 });

 

 

 

this.DataContext = ct;

 

}



Thanks in advance.

0
Tina Stancheva
Telerik team
answered on 02 May 2012, 04:08 PM
Hi Prakash,

I attached a sample solution where I implemented a RadContextMenu on the RadTreeViewItems. The ContextMenu allows you to add and remove items in the self-referencing flat collection displayed in the RadTreeView. Please give it a try and let me know if it helps.

Greetings,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
TreeView
Asked by
TSRG - IT
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Olivier
Top achievements
Rank 1
Selvakumar Savarimuthu
Top achievements
Rank 1
Prakash
Top achievements
Rank 1
Share this question
or