Page 1 of 1

How to sort properly from C#

Posted: Tue Mar 27, 2018 11:38 am
by scoroop
Hello Stimulsoft Team,
Since I haven't found it in samples on github I'll ask this question here. Let's assume I have a simple report where I parametrize it completely from C#. That's how we do it because some reports are automatically generated without any UI overnight. The moment I want to compile a report I need to set sorting. What is the proper way I should do it? Should I find databand and set its sort property or is there any other way?
Thanks in advance

Re: How to sort properly from C#

Posted: Tue Mar 27, 2018 10:22 pm
by Edward
Hi Scoroop,

Yes, that is possible. Please check the following topic:
viewtopic.php?&t=563

Thank you,
Edward

Re: How to sort properly from C#

Posted: Tue Mar 27, 2018 10:56 pm
by scoroop
I have a problem that report never gets into the prerender event handler. What are prerequisites so that it gets called?

Re: How to sort properly from C#

Posted: Wed Mar 28, 2018 6:57 am
by Lech Kulikowski
Hello,

You can add necessary sorting for the DataBand in your code when adding the band to the report, without using events.

Thank you.

Re: How to sort properly from C#

Posted: Wed Mar 28, 2018 7:53 am
by scoroop
Good tip - actually we do have one report that is generated completely from C# code including StiReport. And in this one sorting worked, but those which use StiReport loaded from mrt file and already do have databand - I can't get it work. I suppose in such case there must be some method that is called when databand is added. Perhaps I could call it myself when setting sort property?

Re: How to sort properly from C#

Posted: Wed Mar 28, 2018 4:40 pm
by scoroop
anyone? :)

Re: How to sort properly from C#

Posted: Wed Mar 28, 2018 10:29 pm
by Lech Kulikowski
Hello,

You can add sorting for mrt file also:

Code: Select all

report.Load("report.mrt");
var dataBand = report.GetComponentByName("DataBandName") as StiDataBand;
dataBand.Sort = new string[2] { "ASC", "Name"}; 
Thank you.

Re: How to sort properly from C#

Posted: Thu Mar 29, 2018 7:25 am
by scoroop
That's basically my case. The point is sorting never happens. Therefore I started exploring options like setting Sort property in event handler or calling some method afterwards. Still no solution for me :(

Re: How to sort properly from C#

Posted: Thu Mar 29, 2018 8:34 pm
by Lech Kulikowski
Hello,

Please send us a sample report or project which reproduces the issue for analysis.

Thank you.