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

Binding Complex XML to TreeView

1 Answer 66 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Prakash
Top achievements
Rank 1
Prakash asked on 04 Jan 2012, 03:36 PM
Hi,

Telerik Version: 2010.2.924.1040

Requirement: 

I've a following XML and I want to bind that to RadTreeView, Please help me in doing this task. 

I've seen the following link and found that XML nodes are of same type, XmlNodeItem, Items
Whereas I need an example where the XML has different type of nodes at each level.

http://www.telerik.com/help/silverlight/radtreeview-populating-with-data-data-binding-to-xml.html

The following is sample XML, which is very close to my actual XML. I'm waiting for your response at the earliest. 

<Channels>
       <Channel>
<Name>STAR</Name>
<Programmes>
                      <Program>
<ProgramName>News</ProgramName>
<ProgramID>Star001</ProgramID>
<Duration>30M</Duration>
<Advertisements>
                                            <Advertisement>
<AdvertisementName>Advertisement 1</Advertisement>
 <Advertisement>
<Advertisement>
                                                  <AdvertisementName>Advertisement 2</Advertisement>
                                            </Advertisement>
 </Advertisements>
</Program>
                    <Program>
                               <ProgramName>Movie</ProgramName>
                               <ProgramID>Start002</ProgramID>
                               <Duration>3H</Duration>
                               <Advertisements>
<Advertisement>
<AdvertisementName>Advertisement 1</AdvertisementName>
</Advertisement>
</Advertisements>
                    </Program>
</Programmes>
      </Channel>
       <Channel>
.
.
.
</Channel>
</Channels>

Thanks,
Prakash.

1 Answer, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 09 Jan 2012, 11:11 AM
Hi Prakash,

Basically in order to display multiple child types in the RadTreeViewItems hierarchy, you need to make sure that they inherit one common type. Please note that you can only set one children collection as an ItemsSource in an HierarchicalDataTemplate for each RadTreeViewItem and this is why you need to define only one children collection for each item and populate it with all children items even if they are different.

Please have a look at this forum thread where a similar scenario is described. The approach that is demonstrated there can be used along with the approach for displaying XML data in the RadTreeView (from the help article). Please give it a try and let me know if it helps.

All the best,
Tina Stancheva
the Telerik team

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

Tags
TreeView
Asked by
Prakash
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or