绑定时从当前行获取值
-
22-08-2019 - |
题
我使用的DevExpress XtraReports在WinForms应用程序,但也同样适用于其他的报表工具。
我想在报告中执行每行的一些逻辑,因为它是“呈现”,在一行接一行的基础。具体来说,我想隐藏条形码如果条形码中的数据是不可用的。
目前我做了以下内容:
private void xrBarCode2_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
var barcode = (XRBarCode)sender;
if (barcode.Text.Trim() == "")
{
barcode.Visible = false;
lblWarning.Visible = true;
}
else
{
barcode.Visible = true;
lblWarning.Visible = false;
}
}
但是,这只是普通的味道不好。我想访问当前数据行的这个方法,在对象的“真实”性的工作,但不能。究竟是什么在其他报表生成的典型模式?我是不是即使使用正确的事件?我试图Detail_BeforePrint
,但没有任何附加信息。
解决方案
使用Detail_BeforePrint结合GetCurrentColumnValue()像这样:
private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
if (string.IsNullOrEmpty(GetCurrentColumnValue("BarcodeColumnName"))) {
barcode.Visible = false;
lblWarning.Visible = true;
} else {
barcode.Visible = true;
lblWarning.Visible = false;
}
}
不隶属于 StackOverflow