c# - WinForms programmatic binding of master-detail -


i've got winforms app explorer style treeview on left. selecting different nodes display different usercontrols composed of various other standard controls. of controls within various usercontrols bound single dataset. have combobox above scope of tree (to change between test , live settings) bound master table, , have master-detail relationships setup between tables, changing combobox changes current row child tables. far, good.

i've added plugable sub-trees (picked separate dlls), , each sub-tree uses it's own dataset. part i'm having trouble how make sub-trees link master table. i've replicated master table within sub-trees' datasets (because relations won't work between datasets), because sub-trees don't have own combobox, i'm unsure how make binding work. guess need currencymanager each sub-tree, , somehow link them combobox's change event, how relate sub-tree's usercontrols currencymanager?

the piece missing creating bindingcontext sub-tree...

bindingcontext = new bindingcontext(); 

...and setting on sub-tree's usercontrols:

public partial class myusercontrol : usercontrol {     public myusercontrol(bindingcontext bindingcontext, dataset dataset)     {         this.bindingcontext = bindingcontext;         initializecomponent();         mytextbox.databindings.add("text", dataset, "master.master_detail.detailfield");     } } 

i didn't understand currencymanager doesn't need explicitly created link dataset. setting databindings enough.

keeping 2 separate datasets in step required method this:

public void masterchanged(long masterid) {     var currencymanager = bindingcontext[datamodel.dataset, "master"];     var masterrows = mastertable.rows;     (int position = 0; position < masterrows.count; position++)     {         if (((long)masterrows[position]["id"]) == masterid)         {             currencymanager.position = position;             break;         }     } } 

Comments