Differences between revisions 1 and 2
Revision 1 as of 2011-02-24 14:42:09
Size: 992
Editor: 24-151-193-255
Comment:
Revision 2 as of 2011-02-24 14:44:41
Size: 1193
Editor: 24-151-193-255
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
When using the EntityFramework4.0 You can bind a DataGridView to related entities (linked entities) by using the DataBindingComplete event. For example (From Lerman, J. "Programming Entity Framework" O'Reilly. pp. 199-200): When using the EntityFramework4 You can bind a DataGridView to related entities (linked entities) by using the DataBindingComplete event. For example (From Lerman, J. "Programming Entity Framework" O'Reilly. pp. 199-200):
Line 19: Line 19:

NOTE: In a more highly architected application, you would likely be using pattersn that would not force you to perform this type of logic. E.g. Your application may have a presentation objects layer?

BindingRelatedObjectsToDataGridView

When using the EntityFramework4 You can bind a DataGridView to related entities (linked entities) by using the DataBindingComplete event. For example (From Lerman, J. "Programming Entity Framework" O'Reilly. pp. 199-200):

   1         private void reservationsDataGridView_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
   2         {
   3             DataGridView gridView = (DataGridView)sender;
   4             foreach (DataGridViewRow row in gridView.Rows)
   5             {
   6                 BAGA.Reservation reservation = (BAGA.Reservation)(row.DataBoundItem);
   7                 BAGA.Trip trip = reservation.Trip;
   8                 row.Cells[tripStartColumn.Index].Value = trip.StartDate.ToShortDateString();
   9                 row.Cells[tripEndColumn.Index].Value = trip.EndDate.ToShortDateString();
  10                 row.Cells[destinationColumn.Index].Value = trip.Destination.DestinationName;
  11             }
  12         }

NOTE: In a more highly architected application, you would likely be using pattersn that would not force you to perform this type of logic. E.g. Your application may have a presentation objects layer?

ProgrammingLinks/BindingRelatedObjectsToDataGridView (last edited 2011-02-24 14:46:43 by 24-151-193-255)