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

时间:2009-04-01 15:47:25

标签: c# data-binding report devexpress

我在WinForms应用程序中使用DevExpress XtraReports,但同样适用于其他报告工具。

我希望在报告中逐行执行一些逻辑,因为它是逐行“渲染”的。具体来说,如果条形码的数据不可用,我想隐藏条形码。

目前我正在做以下事情:

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,但没有其他信息。

1 个答案:

答案 0 :(得分:4)

将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;
    }
}
相关问题