Is there a way to access individual instances of repeating elements in DevExpress XtraReports?

I’m working with DevExpress XtraReports and I’ve run into a bit of a snag. I’ve got a subreport that prints multiple times based on query results. I’m using the BeforePrint event on an XRTable in this subreport to do some calculations and change cell text.

The problem is, when I change the text in one instance, it affects all the other instances too. I can work around this by resetting the text each time BeforePrint is called, but it feels like a hack and could lead to bugs.

Is there a better way to handle this? I’d like to be able to modify each instance of the table separately, without affecting the others. Does XtraReports have a feature that lets me access the specific instance being printed, rather than modifying the general template?

Here’s a simplified example of what I’m doing now:

private void xrTable_BeforePrint(object sender, PrintEventArgs e)
{
    XRTable table = sender as XRTable;
    table.Cells[0].Text = GetSomeCalculatedValue();
    // This changes ALL instances of the table
}

Any ideas on how to improve this approach?

hey sophiac, try using report.getcurrentrow() in your beforeprint. that way, you access the exact data row for each instance. a quick example: table.Cells[0].Text = ((DataRowView)report.getcurrentrow())[‘yourField’].tostring(); hope it helps!

I’ve wrestled with this exact issue in XtraReports before. The key is to understand that XtraReports reuses the same control instances for efficiency. To work around this, I’ve found success using the DataSource of the report or subreport to store instance-specific data.

Instead of modifying the control directly, you can bind the cell text to a field in your DataSource. Then, in the BeforePrint event, update that field in the current DataRow. This way, each instance maintains its own data.

Here’s a rough example of how I’ve implemented this:

private void xrTable_BeforePrint(object sender, PrintEventArgs e)
{
    XRTable table = sender as XRTable;
    var currentRow = (sender as XRControl).Report.GetCurrentRow();
    currentRow["CalculatedField"] = GetSomeCalculatedValue();
}

Then, bind your cell’s Text property to the “CalculatedField” in the designer. This approach has served me well in complex reports, allowing for instance-specific modifications without side effects.

Having worked extensively with XtraReports, I can confirm that handling repeating elements can be tricky. One effective approach I’ve used is leveraging the Tag property of the XRControl. In the BeforePrint event, you can store instance-specific data in the Tag, which doesn’t affect other instances.

Here’s a method I’ve found reliable:

private void xrTable_BeforePrint(object sender, PrintEventArgs e)
{
    XRTable table = sender as XRTable;
    if (table.Tag == null)
    {
        table.Tag = new Dictionary<string, object>();
    }
    var instanceData = (Dictionary<string, object>)table.Tag;
    instanceData["CalculatedValue"] = GetSomeCalculatedValue();
    table.Cells[0].Text = instanceData["CalculatedValue"].ToString();
}

This method maintains separate data for each instance without modifying the template directly. It’s clean, efficient, and avoids the pitfalls of global changes.