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

Creating an Treeview item programmatically

4 Answers 181 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 25 Jan 2010, 09:55 PM
Hi..
I need to programmatically create Treeviewitems based upon the data programmatically... I can create the RadTreeViewItem and it's properties. But how do I add a ItemTemplate and DataTemplate programmatically?   ... add the stack panel...  thanks again!!

<telerikNavigation:RadTreeViewItem IsLoadOnDemandEnabled="True" x:Name="InBox" Header="Inbox Emails" DefaultImageSrc="Images/4Inbox.png" OptionType="CheckList" >

             

       <telerikNavigation:RadTreeViewItem.ItemTemplate>

                <DataTemplate>

               <StackPanel Orientation="Vertical">

                   <TextBlock Text="{Binding NAME}"  FontSize="10" />

                </StackPanel>

               </DataTemplate>

         </telerikNavigation:RadTreeViewItem.ItemTemplate>



       </telerikNavigation:RadTreeViewItem>

4 Answers, 1 is accepted

Sort by
0
Bobi
Telerik team
answered on 28 Jan 2010, 09:26 AM
Hi Jon The Nerd,

The preferable way is to define the desired template in the Resourses of the XAML part. After that you can use TemplateSelector to set the template as demonstrated in the following example:
http://demos.telerik.com/silverlight/#TreeView/HierarchicalTemplate

Note also that ItemTemplate is used only when you have DataBinding so if you want to populate the treeview using RadTreeViewItems instead of binding then you do not need ItemTemplate.
You can also take a look at the LoadOnDemand example:
http://demos.telerik.com/silverlight/#TreeView/LoadOnDemand

If this does not help you please let us know. You can also send us some sample code in order to fix it if possible.

Regards,
Boryana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jon
Top achievements
Rank 1
answered on 02 Feb 2010, 01:19 PM
Hi..
Where do I find the DataTemplateSelector ? That is only in the examples?

Can't I just define a DataTemplate? And Set the TreeViewItem to use that?

thanks again
0
Jon
Top achievements
Rank 1
answered on 02 Feb 2010, 01:24 PM
I have the following code...  I just want to set the RadTreeViewItem to use a DataTemplate

RadTreeViewItem tvi = new RadTreeviewItem
tv.Tag = "myTreeItem"
tvi.Header = "Inbox"


tvi.ItemTemplateSelector =  ?

Here's my template...

<datatempalte  x:key="dataTmp">
<stackpanel>
   <Textblock text="{binding NAME}" fontsize=12/>
</stackpanel>
</datatemplate>


thanks


0
Accepted
Valentin.Stoychev
Telerik team
answered on 02 Feb 2010, 01:25 PM
Hello Jon The Nerd,

please check this help article for more info on the data template selector.

All the best,
Valentin.Stoychev
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
TreeView
Asked by
Jon
Top achievements
Rank 1
Answers by
Bobi
Telerik team
Jon
Top achievements
Rank 1
Valentin.Stoychev
Telerik team
Share this question
or