Hello.
I hate asking you for help but it is more than time to admit defeat.
I have spent a long time (I am too embarrased to say how long) trying to find how to :
- Create a tree from a database
- Add Nodes/Edit Nodes
- Save changes back to the database.
This example explained perfectly how to do #1
http://www.telerik.com/support/kb/silverlight/general/populating-treeview.aspx
Sadly, I could not work out how #2 & #3 might be done.
I am assuming that I am the only person who might want to do this, as I cannot find any mention of anyone else asking this sort of question anywhere on the internet.
Bearing in mind that it may be difficult to imagine why anyone in their right mind would want to edit/save a tree to a database, I don't expect anything a like a working example, as I would be the only person it would benefit.
What I would really appreciate though, is a couple of hints or pointers in the right direction?
What would be the best way to approach the problem? What techniques should I learn?
Needless to say, I have carefully looked at all the examples on your website and downloaded every example from this forum, in the hope of shedding some light on things, but with no luck.
I am aware that there are many different ways things might be done, but I am hoping it might be possible to use the example metioned above as a starting point.
Any help at all would be extremly well received. You have been unbelievably helpful in the past so I am looking forward very much to any suggestions you might be kind enough to give me.
Many thanks,
Pete.
9 Answers, 1 is accepted
Since you are using data binding, you should work entirely with the source collection to add/remove items from the TreeView. Please take a look at the following article:
http://blogs.msdn.com/andybrit/archive/2008/03/05/1-22-2008-using-observablecollections-and-databinding-with-silverlight-2.aspx
As to saving changes to the database, please take a look at the following video tutorials:
http://silverlight.net/learn/videocat.aspx?cat=2#HDI2WebServices
You can also take a look at RadGridView QSF examples with a database:
http://demos.telerik.com/silverlight/#GridView/DataUpdates
If you want to save the edited data please subscribe to the Edited event and make the change to the database there.
Let me knwo if this helps.
All the best,
Boryana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Hello Boyana,
Many thanks for you suggestions on how to go about creating a tree from a database, editing that tree and saving the changes back to the database. I will start studying them as soon as I finish writing this.
It looks like I have a hard and frustrating time in front of me before I have any idea of what needs to be done.
Your suggestion of working entirely with the source collection to add/remove items, was very helpful, and that is where I am going to start.
I will probably have one or two more questions oven the following weeks, but in the meantime, could you please tell me if drag and drop works with a bound tree. I tried putting IsDragDropEnabled="True" into your "League" examples, but it did not seem to work. The ability to drag an drop is fundamental to what I am trying to do.
Once again, many thank Boyana.
I hope to hear from you if you have a moment to reply.
Rgards,
Pete.
P.S. If there is anyone out there kind enough drop a hint or two, I suspect I would not be the only one to be eternally grateful :)
Apparently some sort of text is required so I cannot completely remove the message.
I apologise for any inconvenience.
Regards,
Pete.
I am glad that I managed to help you.
Yes, you can use the Drag and Drop functionality of RadtreeView when using binding.
You can find attached a sample project that demonstrates how to use DragDrop with a databound RadtreeView.
In order to test the example please follow these steps:
1.Expand the "Sting" and "DepecheMode" nodes.
2.Expand
Sting
---BrandNewDay
and
DepecheMode
----Violator
3.Select "Clean" from "Violator" items, drag it and drop it in "BrandNewDay" (the tooltip should read: "Drop in BrandNewDay").
Let me knwo if this helps.
Best wishes,
Boryana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Hello Boryana (Sorry I spelt your name incorrectly before)
I am extremely grateful for your example of drag and drop for a bound Treeview.
There is no way I would have been able to work that out on my own.
I cannot believe you wrote something so complete and comprehensive just for me, so I suspect you have a library of examples, and luckily for me, drag/drop was available.
However hard I try I cannot work out how to delete items from the datasource.
ds.Delete(TreeItem) only seems to work for root items.
I don't suppose that library has an example of how to delete items from a bound TreeView does it?
The last think I want to do, is push my luck too far, but it would be great if you could help me out once again.
I must say that programming a TreeView is a LOT harder than I expected.
Many thanks for your excellent help so far,
Regards,
Pete.
Thank you for the good words. I am glad that I managed to help you.
If you want to remove some item from the datasource then you need an appropriate query to the database.
Please take a look at the RadgridView example that shows how to delete items from a datasource:
http://demos.telerik.com/silverlight/#GridView/DataSourceUpdates
So in your occasion, you can try something like:
((IList) this.treeView.ItemsSource).Remove(item);
or
this.RadTreeView1.Items.Remove(item) /this.RadTreeView1.Items.Removeat(index)
If this does not solve your problem please send us some sample code or more details about the type of the datasource you use.
For example you can write something like this:
public static void DeleteOrder(Products product)
{
if (product != null)
{
products.Remove(product);
}
}
Where products is
private static ObservableCollection<Products> products;
and Products is a sample class.
I hope that this will help you.
Regards,
Boryana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Hello Again Boryana,
Many thanks for your reply.
I did not reply immediately, because I was trying to do as you suggested.
Unfortunately I didn't manage to get very far.
I THINK the problem lies in the fact that the datasource used for the tree is hierarchical while the datasource for the grid examples you give are flat, although I may very well be completely wrong. I seem to be able to delete the root items, but no deeper than that.
The database/datasource I am using is EXACTLY like the one used in this excellent example
http://www.telerik.com/support/kb/silverlight/general/populating-treeview.aspx
It would be extremely helpful if it were possible to show how nodes might be deleted from this example, and perhaps explain how to save any changes back to the database :-)
I understand this is asking a great deal but I notice that a lot of great examples are given for your ASP.NET treeview. Maybe Telerik have just not yet got round to producing similar examples for the Silverlight Treeview.
I am beginning to realise that my programming ability may not yet be good enough to use the RadTreeView (or any other treeview) but I honestly didn’t think it would be so hard. It is too late to change direction now so I am hoping you will be kind enough to help even more.
Kind regards,
Meerkat.
It seems that you are looking for an easy way to do CRUD operations for some data. This may be a good time to have a look at the Telerik Northwind demo, that uses a databound TreeView and the Astoria services (Now called ADO.NET Data Services) to add, remove and update elements from a database.
The running demo can be found here:
http://demos.telerik.com/silverlight/northwindbackend/default.aspx
I have attached the source, so you an have a look at it.
Generally once you start using Silverlight/WPF controls you will notice that things are very much alike - for example all ItemsControls have ItemTemplates, ItemContainerStyles, Items and ItemsSource properties (others too).
Binding and modifying any other control is very similar. If this is the first time you are doing this, the TreeView may seem like a bit of a challenge but will set you on the right path for all other controls that are really somewhat simpler. When you know how to bind a Hierarchical HeaderedItemsControl with LoadOnDemand (a.k.a the TreeView), other things will be easier.
Kind regards,
Miroslav
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Crikey! There must be an easier way to earn a living.
I suppose I had better start learning Astoria followed by goodness knows what.
All I wanted to do was show/edit some data in a tree instead of a list. :-(
Thanks for your suggestion Miroslav.
If by some miracle, I manage to get my head round this lot, I will let you know how I got on.
Keep up the good work.
Bye for now.
Meerkat.