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

RadTreeView datatemplate example?

9 Answers 270 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
NS
Top achievements
Rank 1
NS asked on 10 Jun 2008, 08:53 AM
Hello,
I fill a generic list of the type of my own custom object. (it contains an ID, Name, Description),

If I bind the ItemsSource of the Treeview to this list, I get in the visual appearance of the tree in each node"MyApplication.MyObject".

Are there any examples on how to show a field of my object in the tree ? Or how to link a DataTemplate to the tree, and how must this DataTemplate look like ? (multiple hierarchical ?)

Thanks,
Nicolas

9 Answers, 1 is accepted

Sort by
0
Valentin.Stoychev
Telerik team
answered on 10 Jun 2008, 04:00 PM
Hello Nicolas,

Please find attached a sample with treeview control databinded to a collection.

Please let us know if you need any clarifications on the code.


Regards,
Valentin.Stoychev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
NS
Top achievements
Rank 1
answered on 11 Jun 2008, 11:23 AM
Hi,
Thank you for the example, it was really helpful.

I have an additional question:

If I use a datatemplate to display data, and I fill the ItemsSource of the treeview, I can trigger the Selected event of the treeview.

In the selected event, I can cast the tree.SelectedItem to a custom object.

Let's say that you don't fill the ItemsSource of the treeview, but instead create the RadTreeViewItems programatically.

Using 
<Style TargetType="telerik:RadTreeViewItem" x:Key="TreeViewItemStyle"> ...  


and placing something inside this style, the programatically created RadTreeViewItems are displayed.

Problem is inside the Selected event of the treeview, I get an error while trying to cast the SelectedItem to my custom object. Can this be done ?

Thanks,
Nicolas
0
Valentin.Stoychev
Telerik team
answered on 12 Jun 2008, 08:18 AM
Hello Nicolas,

The SelectedItem property always points to the data object that is used from the TreeviewItem - if you are using databinding you will get the object to which the Treeviewitem is bind-ed to. If you create the TreeViewItem declaratively the SelectedItem will always be of type RadTreeViewItem.

There is also a SelectedItemContainer property that always points to the current selected RadTreeViewItem.

So in order to achieve your scenario - when you are creating the RadTreeViewItems programmatically you can set the Tag property to something that will help you to identify your object in the Selected event. You can place some ID, or even the whole object in the Tag property.

Please let us know if you need more help on this.

Regards,
Valentin.Stoychev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
NS
Top achievements
Rank 1
answered on 12 Jun 2008, 08:35 AM
Hi Valentin,
Thank you for the update. I must admit that adding RadTreeViewItems using a foreach loop is a typical way of thinking for me because I'm an asp.net developer.

I worked for a couple of hours to better understand the HierarchicalTemplate way of working, and now it fully works with my code !

This is a very nice way of databinding and getting objects on selecteditems is much cleaner than I would have done it in an asp.net way :-)
0
Valentin.Stoychev
Telerik team
answered on 12 Jun 2008, 08:50 AM
Hi Nicolas,

Yes - the things are a little bit different than the ASP.NET

There are many articles out there targeting WPF styling/binding/etc. - I recommend reading them as a learning resource as the Silverlight programming is pretty much like WPF :)

Kind regards,
Valentin.Stoychev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Ben Hayat
Top achievements
Rank 2
answered on 12 Jun 2008, 01:47 PM
Valentin;

-------quote--------
There are many articles out there targeting WPF styling/binding/etc. - I recommend reading them as a learning resource as the Silverlight programming is pretty much like WPF :)
-------/quote--------

As I was reading your point, I thought about something that I should share it with you.
Not too long ago, You and I has a small discussion on "DeepLinking" and when I posted a question on Ashish Shetty blog, you responded and you also provided a nice link to one of your blogs that was very helpful to understand your point.

You'll see many people coming to your SL and/or WPF products without much strong background in these new technologies, certainly not as much you guys at Telerik.

So, at this stage, not only you have the responsibility of the teaching your own product, but you'll find a bit of education on these new technologies will help tremendously to capture new developers. My suggestion is, (like the about quoted message), to offer links to information that provide support to your product, like you did with me with Deep Linking.
0
Valentin.Stoychev
Telerik team
answered on 13 Jun 2008, 06:43 AM
Hello Ben,

Sure we can help :)

We have just published an online examples using our controls. You can see the full story here:
http://blogs.telerik.com/NikolayAtanasov/Posts/08-06-12/Telerik_s_Online_Store_demo_based_on_RadControls_for_Silverlight_2_Beta_2.aspx?ReturnURL=%2fBlogs.aspx

There is plenty to see - there is a demonstration of the animated wrap panel, tabstrip, numeric up/dn. The transition animation between the pages is done using the Cube control. We will provide later the source code of the application.


About the learning - I strongly recommend Adam Nathan's "WPF Unleashed" book. It will give you a very good start in undestanding the basic concepts behind Silverlight/WPF.


Regards,
Valentin.Stoychev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Ben Hayat
Top achievements
Rank 2
answered on 13 Jun 2008, 01:47 PM
>> We have just published an online examples using our controls. You can see the full story here:<<

Valentin, would it be possible to get the solution to this sample. I think this will be an excellent way showing your controls. If you don't mind, could you please send it to my email address?
Micnet@Ix.Netcom.Com

Thank you in advance!
0
Valentin.Stoychev
Telerik team
answered on 16 Jun 2008, 07:50 AM
Hello All,

Please find attached the source code for the Snowboard Shop application.

Here are the steps to run the examples:
1. Extract the zip file,
2. Start the solution in root folder,
3. Set us startup project "SnowboardShopWeb" website,
4. Set us startup page the "ClientBin/SnowboardShopTestPage.aspx" page.

Let us know if you have any questions.

Sincerely yours,
Valentin.Stoychev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
General Discussions
Asked by
NS
Top achievements
Rank 1
Answers by
Valentin.Stoychev
Telerik team
NS
Top achievements
Rank 1
Ben Hayat
Top achievements
Rank 2
Share this question
or