DevExpress Report Style binding

Date: 2021-11-16

First add styles to the report:

https://docs.devexpress.com/XtraReports/119473/detailed-guide-to-devexpress-reporting/shape-report-data/specify-conditions-for-report-elements/conditionally-change-a-controls-appearance

Add the databinding to the report (eg in beforeprint) for the detail band

// XPO Object
public class SampleAnalysisItem : XPCustomObject
{
	[Browsable(false)]
	[NonPersistent]
	public string ReportStyleName => IsOffSpec ? "xrControlStyleOffspec" : "xrControlStyleNormal";
}

public class CustomReport : DevExpress.XtraReports.UI.XtraReport
{
	public CustomReport()
	{
		BeforePrint += CustomReport_BeforePrint;
		// set the datasource
		DataSource = new List<SampleAnalysisItem>();
	}

	private void CustomReport_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
	{
		if (GetCurrentRow() is SampleAnalysis obj)
		{
			xrTableRow10.DataBindings.Add("StyleName", DataSource, nameof(SampleAnalysisItem.ReportStyleName));
		}
	}
}
55960cookie-checkDevExpress Report Style binding