Both my DataGridViews correctly display the parent and child records. I can also successfully add child records and save them back to my data source (an XML file). However, when I attempt to add a new parent and child, my program throws an exception saying there are no child records to add even though they are present in the detail DataGridView.
So, the issue is that my child records are not being bound to the class when they are new. What am I missing?
My classes are structured like this:
public class Roads
{
public string RoadName { get; set; }
public List<CrossStreet> CrossStreets { get; set; }
}
public class CrossStreet
{
public string CrossStreetName { get; set;}
}
I have 2 DataGridViews and I am binding my classes to them like this:
BindingSource roadBindingSource = new BindingSource();
BindingSource crossStreetBindingSource = new BindingSource();
// _roads contains both the road and cross street data.
roadBindingSource.DataSource = _roads;
crossStreetBindingSource.DataSource = roadBindingSource;
crossStreetBindingSource.DataMember = "CrossStreets";
dataGridViewRoads.DataSource = roadsBindingSource;
dataGridViewCrossStreets.DataSource = crossStreetBindingSource;