ActiveReports Conditional Formatting - Picture Visibility
In ActiveReports, how can I change formatting based on values in the report data?
Specifically, I want to show or hide pictures based on a value in the data. The report gets bound to a list of objects via a set to its DataSource property. These objects ha开发者_Python百科ve a Condition
property with values "Poor", "Normal", etc. I have some pictures in the report that correspond to the different conditions, and I want to hide all the pictures except for the one corresponding to the value.
Should I subscribe to the Format
event for the detail section? If so, how do I get to the "current record" data?
Ok, I still don't know how to get the current data object, but I discovered that you can use the report's Fields
property to retrieve values off the current data object.
The code below subscribes to the detail section's Format
event. Fields["Condition"].Value
gets the value of the current data object's Condition
property (which happens to be an enum value).
private void detail_Format(object sender, EventArgs e)
{
Condition? condition = Fields["Condition"].Value as Condition?;
conditionUnknownPicture.Visible = (condition == Condition.Unknown);
conditionPoorPicture.Visible = (condition == Condition.Poor);
conditionNormalPicture.Visible = (condition == Condition.Normal);
conditionNewPicture.Visible = (condition == Condition.New);
}
Edit:
I've since learned that accessing the Fields collection from a Format event is against the ActiveReports design rules, because it doesn't work in certain weird corner cases. I now use this method instead: http://www.datadynamics.com/forums/ShowPost.aspx?PostID=133642#133642
DataDynamics has a feature request 22786 to provide access to the data objects from Format events.
精彩评论