Merge cells horizontally dynamically

Stimulsoft Reports.NET discussion
Post Reply
wilgri
Posts: 3
Joined: Wed Feb 15, 2023 1:32 pm

Merge cells horizontally dynamically

Post by wilgri »

Hello,

I've been working on a solution for quite a time and tried different approaches without success.

I need to generate a table looking report. I'm not sure anymore, which component to use to achieve that.

What I want to do:

I need a table with 7 static columns for example.
Depending on the content, the cells need to merge together and become a bigger cell.
I would appreciate any approach.
If needed, the solution can be pure C# too.
example.png
example.png (19.86 KiB) Viewed 806 times
Thank you very much.
wilgri
Posts: 3
Joined: Wed Feb 15, 2023 1:32 pm

Re: Merge cells horizontally dynamically

Post by wilgri »

I posted a possible solution to my question here before my thread was approved. Why was my answer deleted?
wilgri
Posts: 3
Joined: Wed Feb 15, 2023 1:32 pm

Re: Merge cells horizontally dynamically

Post by wilgri »

I will try to post my solution again:

Maybe this will help someone who has the same requirements for a special report;

Currently I'm using a consistent working event called "Get Value" for every Cell in the table.
Appearently this event works as assumed like an iteration for every cell from left to right.
On this condition I used some helper variables in the template and a little bit of C# code in the event to "merge" cells.

The logic is quite simple. I "merge" every Cell together, who has the same value in a line/row. There can be multiple merges in a row.
I was generally trying to mimic the "Process duplicate" functionality, but just on the horizontal plane.

What I do in the Get Value Event:

Code: Select all

if(e.Value == lastValue && lastLine == Line)
{
	//mark for merge!
	merge = true;
	(lastComponent as Stimulsoft.Report.Components.Table.StiTableCell).Width += (sender as Stimulsoft.Report.Components.Table.StiTableCell).Width;
	(sender as Stimulsoft.Report.Components.Table.StiTableCell).Enabled = false;
}
else
{
	//save values for next cell
	lastComponent = sender;
	lastValue = e.Value;
	merge = false;
	lastLine = Line;
}
you can try it for yourself, since I added my example report

My question:
Is there a way to achieve the same output but with the use of components and native functionality?
The form and way the datasource is provided can be changed!

I'm open for every suggestion and any help is appreciated!

Thank you very much in advance.
Attachments
sample.mrt
(786.07 KiB) Downloaded 95 times
Lech Kulikowski
Posts: 6197
Joined: Tue Mar 20, 2018 5:34 am

Re: Merge cells horizontally dynamically

Post by Lech Kulikowski »

Hello,

Thank you for your sample.

Unfortunately, there are no standard options for merging horizontally, only via code in events.

Thank you.
Post Reply