我正在使用DevExpress报告,我需要将两个细节行插入一行,例如像这样(每个细节行有1列):
------------------------------------
Detail1 | Detail2
------------------------------------
目前,当我插入详细信息行2时,它会插入详细信息行1下,例如:
-----------------------------------
Detail1
-----------------------------------
Detail2
-----------------------------------
我该如何解决这个问题?
答案 0 :(得分:1)
通过并排放置两个子报告 0 ,可以使用XRSubreport
个对象在一行中显示两个详细信息。因此,只需将两个XRSubreport
对象放到DetailBand
并使用XRSubreport.BeforePrint
事件处理程序为子报告 1 提供详细信息。
这是一个例子:
public void ShowReport()
{
var masters = new List<Master>();
var random = new Random();
for (int index = 0; index < 100; index++)
{
var master = new Master() { ID = index, Name = "Master_" + index };
var detailCount = random.Next(1, 10);
for (int detailIndex = 0; detailIndex < detailCount; detailIndex++)
{
var detail0 = new Detail0() { ID = detailIndex, Name = "Detail_0_" + detailIndex };
master.Details0.Add(detail0);
}
detailCount = random.Next(1, 10);
for (int detailIndex = 0; detailIndex < detailCount; detailIndex++)
{
var detail1 = new Detail1() { ID = detailIndex, Name = "Detail_1_" + detailIndex };
master.Details1.Add(detail1);
}
masters.Add(master);
}
var report = new XtraReport();
var detailBand = CreateDetailBand(report, masters);
detailBand.HeightF = 40;
var detailReport0 = new XtraReport();
CreateDetailBand(detailReport0, null);
var subReport0 = new XRSubreport() { LocationF = new PointF(20, 20), WidthF = 150, ReportSource = detailReport0 };
subReport0.BeforePrint += (s, e) =>
{
var currentReport = ((XRSubreport)s);
var master = ((Master)currentReport.Report.GetCurrentRow());
currentReport.ReportSource.DataSource = master.Details0;
};
detailBand.Controls.Add(subReport0);
var detailReport1 = new XtraReport();
CreateDetailBand(detailReport1, null);
var subReport1 = new XRSubreport() { LocationF = new PointF(170, 20), WidthF = 150, ReportSource = detailReport1 };
subReport1.BeforePrint += (s, e) =>
{
var currentReport = ((XRSubreport)s);
var master = ((Master)currentReport.Report.GetCurrentRow());
currentReport.ReportSource.DataSource = master.Details1;
};
detailBand.Controls.Add(subReport1);
report.DataSource = masters;
report.ShowRibbonPreview();
}
public DetailBand CreateDetailBand(XtraReport report, object DataSource)
{
var detailBand = new DetailBand() { HeightF = 20 };
var label = new XRLabel();
label.DataBindings.Add(new XRBinding("Text", DataSource, "ID"));
detailBand.Controls.Add(label);
label = new XRLabel() { LeftF = 30 };
label.DataBindings.Add(new XRBinding("Text", DataSource, "Name"));
detailBand.Controls.Add(label);
report.Bands.Add(detailBand);
return detailBand;
}
public class Master
{
public Master()
{
Details0 = new List<Detail0>();
Details1 = new List<Detail1>();
}
public int ID { get; set; }
public string Name { get; set; }
public List<Detail0> Details0 { get; private set; }
public List<Detail1> Details1 { get; private set; }
}
public class Detail0
{
public int ID { get; set; }
public string Name { get; set; }
}
public class Detail1
{
public int ID { get; set; }
public string Name { get; set; }
}
这是截图:
0 How to: Create a Side-by-Side Report
1 How to: Create a Master-Detail Report using Subreports