Page 1 of 1

How to write StiExpression for Count() in code

Posted: Mon Feb 26, 2018 4:15 pm
by tpontow
Hello Stimulsoft Support,

i build my Report completly in C# Code. I'm using GroupHeaderBand and GroupFooterBand too. It worked fine so far. Now i want to use the Group Count() for displaying the number of grouped Elements for each group. How can i write the StiExpression with using Count()?

I tried the following but nothing works:

Code: Select all

StiText groupHeaderBandTextComponent = new StiText
                        {
                            ...                            
                            Text = new StiExpression(@"{Count()}"),
                            ...                        };

Code: Select all

StiText groupHeaderBandTextComponent = new StiText
                        {
                            ...                            
                            Text = new StiExpression(@"{{Count()}}"),
                            ...                        };

Code: Select all

StiText groupHeaderBandTextComponent = new StiText
                        {
                            ...                            
                            Text = new StiExpression("{{Format(\"{0}\", Count())}}"),                            
...                        };
Is it possible to use Count() in StiExpression Definition in C# code?

Thanks and regards
Thorsten Pontow

Re: How to write StiExpression for Count() in code

Posted: Wed Feb 28, 2018 6:44 am
by Edward
Hi Thorsten,

Please use the GetValue event of the StiText in order to calculate the required value:

Code: Select all

e.Value = ToString(Totals.Count(GroupHeaderBand1)); 
GroupHeaderCountFromCode.png
GroupHeaderCountFromCode.png (53.63 KiB) Viewed 2025 times
Thank you,
Edward

Re: How to write StiExpression for Count() in code

Posted: Wed Feb 28, 2018 9:46 am
by tpontow
Hi Edward,

thanks for your quick response and support. Your solution works for me! Great! I even can use the text generated from text-Expression and i can set my text depending on the number of group items. Here's my code. Maybe someone can use it.

Code: Select all

private void GroupHeaderTextGetValue(object sender, StiGetValueEventArgs valueEventArgs)
{
    if (sender is StiText text)
    {
        string countText = "(1 Item)";

        if (Totals.Count(text.Parent) > 1)
        {
            countText = $"({ToString(Totals.Count(text.Parent))} Items)";
        }

        valueEventArgs.Value = $"{valueEventArgs.Value} {countText}";
    }
}
Thank you
Thorsten

Re: How to write StiExpression for Count() in code

Posted: Thu Mar 01, 2018 6:21 am
by Edward
Hi Thorsten,

Great! No problem. Thank you for the code snippet, someone will definitely benefit from that one!

Thank you,
Edward