Click here to Skip to main content
15,792,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My XML structure is like this:
<?xml version="1.0" encoding="utf-8" ?>
<category name="Panels">
<category name="Grid"></category>
<category name="Border"></category>
<category name="Stack Panel"></category>
<category name="Canvas"></category>
<category name="Wrap Panel"></category>
<category name="Shape">
<category name="Rectangle"></category>
<category name="Elipse"></category>
<category name="Line"></category>
<category name="Others">
<category name="Button"></category>
<category name="Check Box"></category>
<category name="Radio Button"></category>
<category name="Text Block"></category>
<category name="Text Box"></category>
<category name="Password Box"></category>

and I binded this to a treeview like this:
List<Products> categories = new List<Products>();
XDocument categoriesXML = XDocument.Load("Products.xml");
categories = select.LoadDimensions(categoriesXML.Element("categories"));
this.MyTreeView.ItemsSource = categories;
public List<Products> LoadDimensions(XElement element)
return (from Products in element.Elements("category")select new Products()
Name = Products.Attribute("name").Value,
SubCategories = this.LoadDimensions(Products)

And the treeview is with check boxes. If any check box is selected i need the parent of that child node, parent node and root using linq which needs to return List<>. So that i can bind to another treeview. I wrote like this but it is giving an error: In the below mentioned linq assume rectangle checkbox is selected. So i need rectangle, shape and category to bind it to another treeview.
List<Products> listProd = (from elm in categoriesXML.Element("category").Attribute("name").Value == "Shape"
where elm.Attribute("name").Value == "Rectangle"
select new Products
Name = elm.Attribute("name").Value

I need a LINQ query for the selected nodes. For example if i had selected Rectangle, it is a child of shape and the parent of the shape is categories like this structure i need a list. So that i can bind it to another treeview.
Can some body let me know regarding this issue.

Updated 31-May-10 19:43pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900