I have a very strange issue, and no clue which way I should take to fix it.
I have an IEnumerable and it can cont
I would suggest you use classes, that way it will be easier to see and manipulate the data. Here's an example of what you can do based on the example you gave. The trick is also to keep a reference of the parent inside the child. That you just need to pass the list of child to the grid.
static void Main()
{
var child1 = new List>();
var childOneDic = new Dictionary
{
{ "ChildName", "John" },
{ "ChildAge", 10 }
};
child1.Add(childOneDic);
var child2 = new List>();
var childTwoDic = new Dictionary
{
{ "ChildName", "Tony" },
{ "ChildAge", 12 }
};
child2.Add(childTwoDic);
var parrent = new List>();
var parrentDic = new Dictionary
{
{ "Name", "Mike" },
{ "LastName", "Tyson" },
{ "child1", child1 },
{ "child2", child2 }
};
parrent.Add(parrentDic);
List goodList = new List();
List allChilds = new List();
foreach (Dictionary p in parrent)
{
Parent newParent = new Parent(p);
goodList.Add(newParent);
allChilds.AddRange(newParent.Childs);
}
foreach (Child c in allChilds)
{
Console.WriteLine(c.ParentName + ":" + c.ParentName + ":" + c.Name + ":" + c.Age);
}
Console.ReadLine();
}
public class Parent
{
private List _childs = new List();
private Dictionary _dto;
public Parent(Dictionary dto)
{
_dto = dto;
for (int i = 0; i <= 99; i++)
{
if (_dto.ContainsKey("child" + i))
{
_childs.Add(new Child(((List>)_dto["child" + i])[0], this));
}
}
}
public string Name
{
get { return (string)_dto["Name"]; }
}
public string LastName
{
get { return (string)_dto["LastName"]; }
}
public List Childs
{
get { return _childs; }
}
}
public class Child
{
private Parent _parent;
private Dictionary _dto;
public Child(Dictionary dto, Parent parent)
{
_parent = parent;
_dto = dto;
}
public string Name
{
get { return (string)_dto["ChildName"]; }
}
public int Age
{
get { return (int)_dto["ChildAge"]; }
}
public string ParentName
{
get { return _parent.Name; }
}
public string ParentLastName
{
get { return _parent.LastName; }
}
}
}