How to sort properly from C#

Stimulsoft Reports.NET discussion
Post Reply
scoroop
Posts: 19
Joined: Tue Jul 12, 2016 1:43 pm

How to sort properly from C#

Post 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
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Re: How to sort properly from C#

Post by Edward »

Hi Scoroop,

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

Thank you,
Edward
scoroop
Posts: 19
Joined: Tue Jul 12, 2016 1:43 pm

Re: How to sort properly from C#

Post by scoroop »

I have a problem that report never gets into the prerender event handler. What are prerequisites so that it gets called?
Lech Kulikowski
Posts: 7345
Joined: Tue Mar 20, 2018 5:34 am

Re: How to sort properly from C#

Post 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.
scoroop
Posts: 19
Joined: Tue Jul 12, 2016 1:43 pm

Re: How to sort properly from C#

Post 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?
scoroop
Posts: 19
Joined: Tue Jul 12, 2016 1:43 pm

Re: How to sort properly from C#

Post by scoroop »

anyone? :)
Lech Kulikowski
Posts: 7345
Joined: Tue Mar 20, 2018 5:34 am

Re: How to sort properly from C#

Post 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.
scoroop
Posts: 19
Joined: Tue Jul 12, 2016 1:43 pm

Re: How to sort properly from C#

Post 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 :(
Lech Kulikowski
Posts: 7345
Joined: Tue Mar 20, 2018 5:34 am

Re: How to sort properly from C#

Post by Lech Kulikowski »

Hello,

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

Thank you.
Post Reply