c# - Binding Master Detail data to XtraReport Winforms DevExpress Programtically -
am trying bind data (master details) xtrareport programmatic. if master single data/values means xtrareport working fine. in case master multiple data/values, here details data prints on masters.
eg. (vehicle report) - here 1)cars & 2)bikes master, details of cars master bmw, datsun, hyundai. details of bike master honda, moto, yamaha. want print this
report cars bmw datsun hyundai bikes honda moto yamaha
but printing
report cars bmw datsun hyundai honda moto yamaha bikes bmw datsun hyundai honda moto yamaha
already place labels in designer xtrareports. code prints data on xtrareports programmatic
private void report1_beforeprint(object sender, system.drawing.printing.printeventargs e) { try { strconnection = "provider=microsoft.ace.oledb.12.0;data source=" + properties.settings.default.datapath + @"cmdb\database.mdb"; string qry2 = "select chequeid chqbukid, chdescri chqbukdesc, (select bankname tblbankmaster bank_id=tbchequebook.bankid) bankname tbchequebook"; oledbdataadapter adapter1 = new oledbdataadapter(qry2, strconnection); dataset ds1 = new dataset(); adapter1.fill(ds1, "detail"); ds1.tables[0].tablename = "qrybank"; detailreport.datasource = ds1; xrbinding bindingbankname = new xrbinding("text", ds1, "qrybank.bankname"); txe_bankname.databindings.add(bindingbankname); xrbinding bindingchqbukame = new xrbinding("text", ds1, "qrybank.chqbukdesc"); txe_chequebookdesc.databindings.add(bindingchqbukame); string qry4 = "select chq_no, chq_date, party_name, chq_amount tblchequeleafnew status='p' "; oledbdataadapter adapter3 = new oledbdataadapter(qry4, strconnection); dataset ds3 = new dataset(); adapter3.fill(ds3, "detail2"); ds3.tables[0].tablename = "qrycheque"; detailreport1.datasource = ds3; xrbinding bindingchqno = new xrbinding("text", ds3, "qrycheque.chq_no"); txe_chequeno.databindings.add(bindingchqno); xrbinding bindingchqdate = new xrbinding("text", ds3, "qrycheque.chq_date", "{0:mm/dd/yyyy}"); txe_chequedate.databindings.add(bindingchqdate); xrbinding bindingpartyname = new xrbinding("text", ds3, "qrycheque.party_name"); txe_partyname.databindings.add(bindingpartyname); xrbinding bindingchqamt = new xrbinding("text", ds3, "qrycheque.chq_amount", "{0:n2}"); txe_chequeamount.databindings.add(bindingchqamt); } catch (exception ex) { xtramessagebox.show(ex.message.tostring()); } }
this xtrareport
how solve exact master & details. using above code getting master exactly, show details under masters. answers & suggestion appreciated. in advance.
you need set relations between master , details levels.
if using dataset
need use 1 dataset
object datasource
members , dataset.relations
collection create relations between tables. need use relation name detailreport.datamember
property , use same relation name in bindings.
here example:
private void xtrareport1_beforeprint(object sender, printeventargs e) { var vehicletypes = new datatable("vehicletypes"); vehicletypes.columns.add("type", typeof(string)); vehicletypes.rows.add("cars"); vehicletypes.rows.add("bikes"); var vehicles = new datatable("vehicles"); vehicles.columns.add("type", typeof(string)); vehicles.columns.add("name", typeof(string)); vehicles.rows.add("cars", "bmw"); vehicles.rows.add("cars", "datsun"); vehicles.rows.add("cars", "hyundai"); vehicles.rows.add("bikes", "honda"); vehicles.rows.add("bikes", "moto"); vehicles.rows.add("bikes", "yamaha"); var dataset = new dataset("data"); dataset.tables.add(vehicletypes); dataset.tables.add(vehicles); dataset.relations.add("vehiclesrelation", vehicletypes.columns["type"], vehicles.columns["type"]); datasource = dataset; vehicletypelabel.databindings.add("text", dataset, "type"); vehicledetailreport.datamember = "vehiclesrelation"; vehiclelabel.databindings.add("text", dataset, "vehiclesrelation.name"); }
Comments
Post a Comment