views:

417

answers:

1

I'm using DevExpress XtraReports in a WinForms application, but could equally apply to other reporting tools.

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. 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.

+1  A: 

Use Detail_BeforePrint in conjunction with GetCurrentColumnValue() like so:

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