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
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.
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.
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
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.
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
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
this example set me on the right track and it works great for me, thanks a lot !!
Best regards
Olivier.
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.
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 >>