Build class structure for Hierarchy

on1way

New Member
Given below is my class structure I am trying to build a class which can store and I can access the hierarchy of data given below. To summarize in words (please see Hierarchy illustrated below after the code);
All Regions have only 1 Master Region
Under a Region there can be one or more Locations. \[code\] public class RegionLocItemView { public Guid Id { get; set; } public string name { get; set; } public Guid value { get; set; } public bool isChecked { get; set; } public List<RegionLocItemView> Children { get ; set { //where do i set this from } ; } public RegionLocItemView(List<RegionLocItemView> a) { Children = a; } public RegionLocItemView() { } } /// end of class Accessing class from code below: var getAvailableLocations = Model.SessionProvider.GetAvailableLocations.Where(e => e.Location.Count >= 1); Guid parentid = Guid.Empty; RegionLocItemView cls = new RegionLocItemView(); List<RegionLocItemView> main = new List<RegionLocItemView>(); foreach (var a in getAvailableLocations) { if (a.ParentID == null) { //found Parent of all regions. //cls = new RegionLocItemView(); cls.Id = a.ID; parentid = a.ID; cls.name = a.RecordName; //main.Add(cls); // break; } if (a.ParentID == parentid) { RegionLocItemView cls1 = new RegionLocItemView(); //found children cls1.Id = a.ID; parentid = a.ID; cls1.name = a.RecordName; cls.Children.Add(new List<RegionLocItemView>(cls1)); } } \[/code\]I need to have an IEnumerable collection List to stored objects in the hierarchy below.\[code\] Main Region1 Location1 Location2 Location3 Region2 LocationA LocationB LocationC Region... Location... \[/code\]Questions: Can you refactor my class structure above for the data above, and provide me with a code sample of how I can access the class in C# code. I am reading the above data from an IEnumerable collection and the data is not arranged well and hence I need to do the above. Why do I want this class structure: I want this so that I can bind this to a Telerik TreView control that accepts an IEnumerable collection like a Generic List.
 
Back
Top