Page 1 of 1

Postprocessing report - Problem with ClickEvent

Posted: Fri Sep 27, 2013 11:28 am
by tpontow
Hello Stimulsoft,

in my sample report i implemented a postprocessing step after the report is rendered. In that step i assign a random textbrush to all StiText components as follows:

Code: Select all

report.Compile();
report.CompiledReport.EndRender += DoPostProcessing;

Code: Select all

private void DoPostProcessing(object sender, EventArgs eventArgs)
        {
            StiReport report = sender as StiReport;

            if (!ReferenceEquals(report, null))
            {
                Random r = new Random();
                foreach (StiPage renderedPage in report.RenderedPages.Items)
                {
                    StiComponentsCollection componentsCollection = renderedPage.GetComponents();
                    foreach (var component in componentsCollection)
                    {
                        StiText textComponent = component as StiText;
                        if (!ReferenceEquals(textComponent, null))
                        {
                            textComponent.ComponentGuid = Guid.NewGuid().ToString();
                            textComponent.TextBrush = new StiSolidBrush(Color.FromArgb(r.Next(1, 256), r.Next(1, 256), r.Next(1, 256)));
                            textComponent.Click += TextComponentOnClick;
                        }
                    }
                }
            }

        }
This works fine so far. After that all StiText components have random colors. Great.

But i also like to register a click event to every StiText component. The handler method should output the name, value and ComponentGuid of every single text component. But that does not work. After clicking on a text component no value is shown and the handler method is called for every component with same name.

Code: Select all

 private void TextComponentOnClick(object sender, EventArgs eventArgs)
        {
            StiText text = sender as StiText;

            if (!ReferenceEquals(text, null))
            {
                Trace.WriteLine(string.Format("Click on {0} ({2}). Value: {1}", text.Name, text.TextValue, text.ComponentGuid));
            }
        }
What to do to assign a click event handler to every instance so that i can output the value/textvalue of the component i've clicked on?

I attached sample project as zip file.

Thanks
Thorsten Pontow

Re: Postprocessing report - Problem with ClickEvent

Posted: Fri Sep 27, 2013 12:16 pm
by tpontow
Currently i'm, using build 2013.2.1606.0.

Re: Postprocessing report - Problem with ClickEvent

Posted: Fri Sep 27, 2013 1:31 pm
by HighAley
Hello, Thorsten.

Sorry, we need some additional time to prepare an answer for you.

Thank you.

Re: Postprocessing report - Problem with ClickEvent

Posted: Sun Oct 06, 2013 10:03 pm
by Ivan
Hello, Thorsten.

Please modify your code:

Code: Select all

        private void DoPostProcessing(object sender, EventArgs eventArgs)
        {
            StiReport report = sender as StiReport;

            if (!ReferenceEquals(report, null))
            {
                Random r = new Random();
                System.Collections.Hashtable names = new System.Collections.Hashtable();
                foreach (StiPage renderedPage in report.RenderedPages.Items)
                {
                    StiComponentsCollection componentsCollection = renderedPage.GetComponents();
                    foreach (var component in componentsCollection)
                    {
                        StiText textComponent = component as StiText;
                        if (!ReferenceEquals(textComponent, null))
                        {
                            textComponent.ComponentGuid = Guid.NewGuid().ToString();
                            textComponent.TextBrush = new StiSolidBrush(Color.FromArgb(r.Next(1, 256), r.Next(1, 256), r.Next(1, 256)));
                            if (!string.IsNullOrEmpty(textComponent.Name) && (!names.ContainsKey(textComponent.Name)))
                            {
                                textComponent.Click += TextComponentOnClick;
                                names[textComponent.Name] = textComponent.Name;
                            }
                        }
                    }
                }
            }

        }

        private static void TextComponentOnClick(object sender, EventArgs eventArgs)
        {
            StiText text = sender as StiText;

            if (!ReferenceEquals(text, null))
            {
                Trace.WriteLine(string.Format("Click on {0} ({2}). Value: {1}", text.Name, text.Text.Value, text.ComponentGuid));
            }
        }

Thank you.

Re: Postprocessing report - Problem with ClickEvent

Posted: Tue Oct 08, 2013 1:54 pm
by tpontow
Hello Ivan,

ok, that solution works for me!

Thanks and regards
Thorsten Pontow

Re: Postprocessing report - Problem with ClickEvent

Posted: Wed Oct 09, 2013 6:02 am
by HighAley
Hello, Thorsten.

We are very glad to help you.
Let us know if you need any additional help.

Thank you.

Re: Postprocessing report - Problem with ClickEvent

Posted: Fri Oct 11, 2013 8:26 am
by tpontow
Hello Aleksey,

the problem was a little more complex than i thought. The report was ok all the time. But in my project i serialized the report using SaveDocument() and then i opened the report MDC-document (converted to Binary) again with a viewer control. But none of the events i had in the original report where serialized into the binary and also none of the tag value objects i used.

I solved that special problem by recreating the events after sending the binary report document to the viewer.

Thanks again and reagards
Thorsten

Re: Postprocessing report - Problem with ClickEvent

Posted: Fri Oct 11, 2013 11:55 am
by HighAley
Hello.

It's impossible to serialize events in mdc-document. So the only way is to add events again.

Thank you.