wpf - How to Binding composition based Observable Collection? -
say model looks shown below,
public class organization private string _organizationname; private list<employee> _employees; private list<contractor> _contractors; public string organizationname { { return _organizationname; } set { _organizationname= value; } } public list<employee> employees { { return _employees; } set { _employees = value; } } public list<contractor> contractors { { return _contractors; } set { _contractors = value; } } }
}
public class employee { public string name { get; set; } public int empid { get; set; } public double salary { get; set; } } public class contractor { public string name { get; set; } public int contractorid { get; set; } public double experiancecredit { get; set; } }
i have 1 view(mainwindow) , 1 associated viewmodel(organizationviewmodel)
view(mainwindow)
has 3 controls:
1) listview -organizationlistview 2) datagrid -employeesdatagrid 3) datagrid -contractorsdatagrid
viewmodel(organizationviewmodel)
private observablecollection<organization> _organizations public observablecollection<organization> organizations { {`enter code here` return _organizations; } set { _organizations = value; } }
binding:
listview - organizationlistview - binds organizations(observablecollection) datagrid - employeesdatagrid - binds organizations.employees datagrid - contractorsdatagrid - binds organizations.contractors
i have problem accessing employees & contractors organizations(observablecollection) while trying bind respective control in view?
employeesdatagrid & contractorsdatagrid should dependent on organizationlistview
is achievable or should follow different approach?
what trying do, if understand have list of organizations, when click on 1 of organizations table of employees , contractors organization shown in data grids. right?
if so, doing hard way. want create relation between organization table , contractor table , separate relation between organization table employee table. doing poco fool's errand in view.
the many ways this, first choice typed dataset. setup 3 tables , 2 relations, create view model containing instantiated dataset. bind organization table list view , 2 relations datagrids , done!
Comments
Post a Comment