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:
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:
-- 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
Post a Comment