Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Databinding two grids - parent child from entity framework

$
0
0

I cannot find any examples of binding a parent and child grid where the datasource is entity objects. I need the two grids to be in sync - when parent record is selected in parent grid, child records should display in child grid. Here is my attempt:

Employees = parent entity

EmployeeForms = child entity

var results = from ncrecord in admincontext.Employees.Include("EmployeeForms")
                          where ncrecord.EmployeeForms.Any(p => p.DueDate < DateTime.Now)
                          select ncrecord;

results.Load();

grdParent.DataSource = bindingSourceEmployees;
grdChild.DataSource = bindingSourceForms;

 bindingSourceEmployees.DataSource = dbcontext.Employees.Local.ToBindingList(); // have also tried just dbcontext

bindingSourceEmployees.DataMember = ??; // "Employees" does not work - DataMember property 'Employees' cannot be found on the DataSource.

 bindingSourceForms.DataSource = bindingSourceEmployees;

bindingSourceForms.DataMember = ??; // have tried name of relation

I can't use the entity name for datamember, or the data relationship. Both cause errors.


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>