c# - Devexpress master-detail in 2 gridcontrols -


how display master-detail view in 2 grids instead of 1 grid. here's how populate grid , show master-detail view.

i don't know how set relation or datamember property (as shown in examples use database) in case of using 2 grid controls create relation current data structure.

 public class master  {       public int id { get; set; }       public list<sub> subs { get; set; }  }  public class sub {     public int id { get; set; }     public string name { get; set; } }  //filling data master , sub objects private void filldata() {     master = new list<master>();     (int = 0; < 10; i++)      {         master tmpmaster = new master();         tmpmaster.id = i;         tmpmaster.name = "master " + (i + 1).tostring();         tmpmaster.subs = new list<sub>();         for(int j = 0; j < 5; j++)         {             sub tmpsub = new sub();             tmpsub.id = j;             tmpsub.name = "sub " + (j + 1).tostring();             tmpmaster.subs.add(tmpsub);         }         master.add(tmpmaster);     }  }  filldata(); grid = new gridcontrol(); this.controls.add(grid); grid.datasource = master; 

thanks suggestions.

i think want 2 binding sources. first binding source, bindingsourcemaster bound @ design time master:

bindingsourcemaster.datasource = typeof(master); 

then can bind second binding source, bindingsourcesub subs property of bindingsourcemaster. easiest way @ design time this:

enter image description here

which create code in .designer file:

//  // bindingsourcesub //  this.bindingsourcesub.datasource = this.subsbindingsource; //  // subsbindingsource //  this.subsbindingsource.datamember = "subs"; this.subsbindingsource.datasource = this.bindingsourcemaster; 

(but don't worry -- let designer heavy lifting)

gridcontrolmaster's datasource bindingsourcemaster, , gridcontrolsubs's datasource bindingsourcesubs.

from there, .net , dev express of heavy lifting you. once assign object bindingsourcemaster, else work expected:

list<master> _masterlist = getmasteritems();  bindingsourcemaster.datasource = _masterlist; 

now, when change active record in gridcontrolmaster, see gridcontrolsubs automatically displays corresponding detail records selected master:

enter image description here

-- edit --

here fake data, it's worth:

for (int = 1; < 100; i++) {     master m = new master() { id = i, subs = new list<sub>() };      (int j = 1; j < 20; j++)     {         sub s = new sub() { id = * 1000 + j, name = guid.newguid().tostring() };         m.subs.add(s);     }      master.add(m); }  bindingsourcemaster.datasource = master; 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -