I need to fill a tree-like UI control with some items (of course in parent-child1-child2-…childN relations) and before proceeding I want to ensure that the my collection that holds the content is ordered properly as follows:
Each object(in this case an instance of my Category class) from my collection (ObservableCollection that is not ordered) has a public property(a ParentCategoryID as string) that points to another ‘Category’ that will be its parent in my tree. A node in the tree can have 0 or any number of children.
So when filling the tree, each ‘category’ object that is to be displayed has already its ‘parent category'(based on the ParentCategoryID) in the collection.
What algorithm should I use to ensure that my collection is ordered this way before addig the elements in the tree?
I’m not sure if this is what you are looking for but hopefully it will help: