Am very much new to Active reports. I want to use External style sheets for all the controls on the Report layout, i goggled it but dint find appropriate article . Is style sheet concept possible if possible how ?
Thanks in advance
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
adla praveenPosted May 13, 2016, 9:13 AM
Bhuvanesh MohankumarPosted May 4, 2016, 2:06 AM
The concept is simple ( perhaps too simple, and I might be missing something )…
1 – Create a template report that will be used to define ALL of the styles used throughout any report. Each style would indicate a font, color, size, etc.
Ex:
StandardDetailText = (Arial, 14, black), StandardHeaderText = (Arial, 16, black), etc. (haven’t given much thought to the names and types yet)
2 – At runtime, as part of our report running framework, both the report to run AND the template report will be referenced in code and their styles (StyleSheet collection) ‘merged’.
That is, the styles defined in the template report that don’t exist in the data report will be added to the ‘StyleSheet’ collection. Currently, I’m calling this function when the report starts (actually form_load in my prototype) and setting a parameter (sourceStyleStart) to 4, to tell the loop to skip the ‘Normal’, ‘H1′, H2′, etc. styles which would be defined by default in both reports (to avoid duplicates). I plan to switch this to add any that don’t exist with a try-catch block.
BTW – I believe it would have been nicer to have been able to use a foreach loop on the Style objects in the Style collection and add the entire object, but looks like one of those classes would need to implement the IEnumerable interface to allow that. It doesn’t, so I figured out to use the Value property, which is fine.
Ex:
The routine might look something like this…
// Add styles from another report
private void MergeStyles(
DataDynamics.ActiveReports.ActiveReport sourceStyleRpt,
DataDynamics.ActiveReports.ActiveReport targetStyleRpt,
int sourceStyleStart
)
{
// Initialization
if (sourceStyleStart.Equals(null))
{
sourceStyleStart = 0;
}
// Add the Styles
for (int i = sourceStyleStart; i < sourceStyleRpt.StyleSheet.Count; i++)
{
// Get the style name
string newStyleName = sourceStyleRpt.StyleSheet.Name;
targetStyleRpt.StyleSheet.Add(newStyleName);
// Set all attributes of the style, as the add above only added the style name, not the object
targetStyleRpt.StyleSheet[newStyleName].Value = sourceStyleRpt.StyleSheet[newStyleName].Value;
}
3 – At runtime, code in each report will reference the appropriate style name from the template report.
Ex:
// Reference a ‘template’ style from this ‘data’ report
private void Detail_Format(object sender, System.EventArgs eArgs)
{
this.Detail.AddBookmark(txtCountry.Text);
this.txtCountry.ClassName = “MyNewStyle3″;
}
Two things to note here. First, this was just the prototype, so on second thought, I wonderif I couldwrite a routine to run at the beginning to do this instead of setting the ClassName for each detail record? Second, this would obviously be a pain to maintain, so I was thinking of writing a routine to determine the default ClassName based on the control type, or something like that. For example, TextBoxes are ‘StandardDetailText’ styles, etc. Not sure yet. Maybe it’ll be table or xml driven for each report, control, etc. I’m thinking that data would probably not change. I’ll set it up to allow it to be overridden. Perhaps a rule like, “If ClassName is null then call new GetClassName method, otherwise, leave what’s there”.