简体   繁体   English

数据绑定时从当前行获取值

[英]Obtain values from current row when databinding

I'm using DevExpress XtraReports in a WinForms application, but could equally apply to other reporting tools.我在 WinForms 应用程序中使用 DevExpress XtraReports,但同样可以应用于其他报告工具。

I'd like to perform some logic per-row in the report as it is "rendered", on a row-by-row basis.我想在报告中逐行执行一些逻辑,因为它是“渲染”的。 Specifically I'd like to hide a barcode if the data for the barcode isn't available.具体来说,如果条码的数据不可用,我想隐藏条码。

Currently I'm doing the following:目前我正在做以下事情:

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;
    }
}

But that just plain smells bad.但这只是闻起来很糟糕。 I'd like to access the current data row in this method and work on the "real" properties of the object, but can't.我想访问此方法中的当前数据行并处理 object 的“真实”属性,但不能。 What is the typical pattern for this in other report generators?在其他报告生成器中,这种情况的典型模式是什么? Am I even using the correct event?我什至使用正确的事件吗? I tried Detail_BeforePrint , but that had no additional information.我尝试Detail_BeforePrint ,但没有其他信息。

Use Detail_BeforePrint in conjunction with GetCurrentColumnValue() like so:将 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;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM