以下給出了我的類結構我正在嘗試構建一個類,它可以存儲並可以訪問下面給出的數據層次結構。爲Hierarchy構建類結構
用文字總結(請參閱下面的代碼後的層次結構);
所有地區只有1個主地區
在地區下可以有一個或多個地點。
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));
}
}
我需要一個IEnumerable集合列表存儲在下面的層次結構中的對象。
Main
Region1
Location1
Location2
Location3
Region2
LocationA
LocationB
LocationC
Region...
Location...
問題:
你能修改我的類結構之上的上述數據,並提供給我的我如何在C#代碼訪問類的代碼示例。我正在從IEnumerable集合中讀取上述數據,數據排列不好,因此我需要執行上述操作。
爲什麼我想要這個類結構:我想這樣就可以將它綁定到Telerik TreView控件,該控件接受像通用列表這樣的IEnumerable集合。
請解決您的格式爲可讀。 – millimoose
@millimoose:您可以在哪裏查看代碼。任何建議都是值得歡迎的。謝謝。 – Ruruboy