c# - Display all child records of a parent in DataGridView -


i new .net, , don't understand how works. have project have , i'm asked display parent records, , when select parent record there should displayed children. far managed display parent records, using datagridview.

private void display_btn_click(object sender, eventargs e)         {             dg.datasource = data_set.tables[0];         } 

the following code works displays records child. know should compare somehow primary key parent foreign key child , display child equal pk parent, don't know how write it.

private void dg_cellcontentclick(object sender, datagridviewcelleventargs e)         {              dg2.datasource = data_set.tables[1];          } 

the code creating relation

 datacolumn parentcolumn = data_set.tables["airline"].columns["airline_id"];                 datacolumn childcolumn = data_set.tables["plane"].columns["airline_id"];                  rel_pln_air = new datarelation("fk_pln_air", parentcolumn, childcolumn);                 data_set.relations.add(rel_pln_air); 

the code binding:

parentbindingsource.datasource = data_set;             parentbindingsource.datamember = "airline";             childbindingsource.datasource = parentbindingsource;             childbindingsource.datamember = "plane"; 

you must define mster-details relation between tables[1] , tables[2] in dataset. must set datasource of child datagridview relation.

walkthrough: creating master/detail form using 2 windows forms datagridview controls detailed explanation of problem.

update

the airline_id can't related plane_id. thing have airline_id in plane table must reference.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -