I am currently using a DataGridView coupled with a subform to implement a master/detail setup. The DataGridView only supports row selection and deletion events - editing/adding items is entirely handled in the subform.
As such, I maintain a list of entities that I make changes to, while binding the DataGridView to a list of anonymous types that I get from a DataContext query. I would like to instead build that a-type list from a query on the list of entities I already loaded, so that I don't have to persist the DataContext. Unfortunately, doing this prevents the row deletion event from firing in the DataGridView.
So basically, what's the difference between:
List<DogOwner> dogOwners = (from d in DataContext.DogOwners
select d)
.ToList();
dataGridView.DataSource = from d in DataContext.DogOwners
select new
{
Name = d.Name,
DogsOwned = d.Dogs.Count
};
and:
List<DogOwner> dogOwners = (from d in DataContext.DogOwners
select d)
.ToList();
dataGridView.DataSource = from d in dogOwners
select new
{
Name = d.Name,
DogsOwned = d.Dogs.Count
};
that it affects the deletion? How can I enable deletion in the latter example? If you're wondering why I don't handle all entity changes in the DataGridView, the form requires changes to be made to an entity and its child entities at the same time. As suggested in the examples, the DataGridView pulls item summaries from parent and child columns.