grounder

grounder

  • NA
  • 3
  • 3.2k

WPF TreeView + LINQ problem

May 7 2012 6:55 AM
Hello,

some days ago I have found a problem while trying to make TreeView in my WPF + LINQ application. In my database I have an table PC_ProductCategories, which looks like this:

PC_ID - primary key
PC_NAME - name of category
PC_PC_ID - foregin key, which direct to the same table.

By foregin key PC_PC_ID I make child/parent structure, so every category have in PC_PC_ID it's parent's ID.

In my XAML it looks like this:


 <TreeView ItemsSource="{Binding Path=ProductCategoriesToShow}" ...>  <TreeView.ItemTemplate>  <HierarchicalDataTemplate ItemsSource="{Binding Path=PC_ProductCategories}">  <TextBlock Text="{Binding Path=PC_NAME}" />  </HierarchicalDataTemplate>  </TreeView.ItemTemplate>  </TreeView>



TreeView take it almost okey - the categories which have children are possible to "open" and I can see their children,
but the problem is - on the "ground" "0" level (just as everything is closed), the TreeView shows all the categories (so the children are doubled, because they're the "0" level, and on their good levels of treeview). Is it still problem of my xaml or binding, or I really need to make next class by hand to just keep something like "String Name; IList<category> listOfChildren"?

Answers (1)