Joining strings from a business object

Stimulsoft Reports.WPF discussion
kro
Posts: 27
Joined: Fri Oct 19, 2012 11:25 am

Joining strings from a business object

Post by kro »

Hello

I have a problem that seems quite simple and yet I cannot find a satisfying solution for it. I have a business object that holds a list of string values and I want to display those values as one string, with a selected separator, let's say, a comma. The important thing is that I want the concatenation of strings to be done in the report itself.

Normally I would do something like this:

Code: Select all

singleString = string.Join(", ", listOfStrings)
In this case this will not work, because the strings in the business object are not really an array and - as far as I understand it - the only way to access every string in the business object is to iterate through them using a data band. So, I can set up a data band and in the rendering event of this data band I can add every value to the target single string, like this:

Code: Select all

singleString += MyBusinessObject.Items.Data + ", ";
This works fine, but I don't like that solution because I don't want to add another data band only for the purpose of concatenating strings.

Another solution is to join the strings and add the single string to the business object, but as I mentioned - I want the operation to be performed in the report itself.

Is there any other way to achieve this?

I'm uploading a sample project that illustrates my problem and a sample report (the report is also included in the project).
Attachments
Report.mrt
(7.35 KiB) Downloaded 734 times
JoiningStrings.zip
(1.75 MiB) Downloaded 527 times
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Joining strings from a business object

Post by Alex K. »

Hello,

There is the Func.EngineHelper.JoinColumnContent(DataSourceName, "ColumnName", delimiter) for StiDataSource.
We try to expand this function and for business objects also.

Thank you.
kro
Posts: 27
Joined: Fri Oct 19, 2012 11:25 am

Re: Joining strings from a business object

Post by kro »

That looks like just the thing I need. I hope it will be available for business objects soon.

Thank you.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Joining strings from a business object

Post by Alex K. »

Hello,

We are always glad to help you!
We will let you know about the result.

Thank you.
kro
Posts: 27
Joined: Fri Oct 19, 2012 11:25 am

Re: Joining strings from a business object

Post by kro »

Hello again

I have been trying to find a workaround for this issue, because for me this problem is not just about joining strings but mostly about accessing the elements of arrays/collections passed to the report as business objects - in some cases I want to be able to perform operations on these elements in the report itself.

With a little bit of effort and some guessing, I came up with two solutions. In the Code tab in my report I have two methods:

Code: Select all

private string JoinStrings()
{
	List<string> data= new List<string>();

	Documents.ComboItems.Connect();
	Documents.ComboItems.First();

	while (!Documents.ComboItems.IsEof) 
	{
		data.Add(Documents.ComboItems.Name);
		Documents.ComboItems.Next();
	}		

	return data.Any() ? data.Aggregate((i1, i2) => i1 + ", " + i2) : string.Empty;
}

private string JoinStringsWithCasting() 
{
	var items = (IEnumerable<ComboItem>)Documents.ComboItems.BusinessObjectValue;
			
	var data = items.Select(i => i.Name);

	return data.Any() ? data.Aggregate((i1, i2) => i1 + ", " + i2) : string.Empty;		
}
JoinStrings() uses the Next() method of the StiBusinessObject class to loop through my data source and access the property that I am interested in. JoinStringsWithCasting() gets the value of the business objects and casts it as ComboItem, which is a type that I define in my sample project.

Both of these methods work. The second one is really nice to use, because it lets me operate on my own types. As for the first one, I am not sure if it is correct, because the members of StiBusinessObject are not very well documented in the class reference - I had to do some guessing here.

My question is: is it OK (safe) to use methods like these?

Naturally, I'm adding attachments with the report template and a sample project (template also included in zip).
Attachments
Report.mrt
(9.4 KiB) Downloaded 645 times
JoiningStrings.zip
(1.75 MiB) Downloaded 503 times
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Joining strings from a business object

Post by Alex K. »

Hello,

Ok.
Thank you for the information.
We will let you know when the function for business objects will be added in the designer.

Thank you.
Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

Re: Joining strings from a business object

Post by Ivan »

Hello,

We add the new overload of function Func.EngineHelper.JoinColumnContent(BusinessObjectName, "ColumnName", delimiter).
Please check the last prerelease build.

Thank you.
kro
Posts: 27
Joined: Fri Oct 19, 2012 11:25 am

Re: Joining strings from a business object

Post by kro »

Hi,

maybe I'm missing something but it seems that there is no overload for this function in the prerelease version 2013.2.1606 (from 24.05).

I know that the list of changes says it was added. I created a new blank project, added reference to Stimulsoft.Report.dll (version 2013.2.1606) and there is no such overload.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Joining strings from a business object

Post by Alex K. »

Hello,

Sorry for the mistake. Due to technical reasons this fix has not been included in the previous build.
The new function will be available in the next prerelease build on this week.

Thank you.
kro
Posts: 27
Joined: Fri Oct 19, 2012 11:25 am

Re: Joining strings from a business object

Post by kro »

Ok, in that case I'll check it next week, thank you.
Post Reply