I'm trying to figure out how to programmatically set up a hierarchical grid bound to a collection of objects. When I run the code shown below I get an exception when trying to expand the parent rows
In the form code behind-
public
Form1()
{
InitializeComponent();
List<Parent> parents =
new
List<Parent> ();
parents.Add(CreateParent(
"Joe"
));
parents.Add(CreateParent(
"Bob"
));
this
.parentBindingSource.DataSource = parents;
}
private
static
Parent CreateParent (
string
parentName)
{
var parent =
new
Parent () {ParentName = parentName};
String childName = String.Format (
"Child of {0}"
, parentName);
parent.Children.Add(
new
Child() { Age = 2, ParentName = parentName, ChildName =
"Child"
});
return
parent;
}
Data class
public
class
Parent
{
private
List<Child> m_children =
new
List<Child> ();
public
String ParentName {
get
;
set
; }
public
MyEnum FirstSecond {
get
;
set
; }
public
List<Child> Children {
get
{
return
m_children; }
private
set
{ m_children = value; } }
}
public
class
Child
{
public
String ChildName {
get
;
set
; }
public
String ParentName {
get
;
set
; }
public
MyEnum FirstSecond {
get
;
set
; }
public
int
Age {
get
;
set
; }
}
public
enum
MyEnum
{
First,
Second
}