Quantcast
Channel: Problem with TreeView
Viewing all articles
Browse latest Browse all 5

Problem with TreeView

$
0
0

>>I think the second one would work, but now that you seen more of the code, I do appreciate your thoughts and opinions on how I should solve the problem with the child leaves.

The PartsList class doesn't seem to contain any property that contains other PartsList objects so it is not hierarchical...You need to add a collection property to the PartsList class that returns the child parts of that particular PartsList object. I have already provided you with such an example: https://social.msdn.microsoft.com/Forums/vstudio/en-US/fdebbcf9-6e3d-4be6-b110-728154305d1c/wpf-treeview-get-child-and-parent?forum=wpf. The Discipline class has a Tests property that returns a collection of Test objects. In this case you set the ItemsSource property of the HierarchicalDataTemplate to "Tests". You need to add a corresponding collection property to your class if you intend to display hierarchical items in a TreeView:

public class PartsList
{
        public long PartsListID { get; set;}
        public long? PartID { get; set;}
        public long? VendorID { get; set;}
        public string VendorName { get; set;}
        public string VendorPartNo { get; set;}
        public string VendorPartNoLink { get; set;}
        public double? Price { get; set;}
        public string Alternative { get; set;}
        public string AlternativeLink1 { get; set;}
        public string AlternativeLink2 { get; set;}
        public string AlternativeLink3 { get; set;}
        public string Description { get; set;}
        public virtual StockControl StockControl { get; set;} public ICollection<PartsList> Children {get;set;}
 public bool IsParent {get { return this.Children != null && this.Children.Any(); }}
}

Then you set the ItemsSource of the HierarchicalDataTemplate to the Children collection, put all TextBlocks in the same HierarchicalDataTemplate and use a DataTrigger that binds to some property (IsParent) of a PartsList that determines whether it is a leaf or parent node and then change the Visibility property of the TextBlocks to be shown/hidden as I explained in my previous reply.

<HierarchicalDataTemplate DataType="{x:Type local:ParentPart}" ItemsSource="{Binding Children}">
                    ...</HierarchicalDataTemplate>

You won't be able to display hierarchical data unless the PartsList class has any collection property.

And just taking some auto generated Entity Framework class and plug it in into a solution as-is is rarely going to work in a real time scenario. You will have to modify or wrap the POCO class to make it adopt to your WPF requirements. In this case you have to add a collection property to it and populate it with the child objects for each PartsList.

Hope that helps.

Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.


Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>