Page 1 of 1

Merge cells horizontally dynamically

Posted: Wed Feb 15, 2023 1:45 pm
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 909 times
Thank you very much.

Re: Merge cells horizontally dynamically

Posted: Fri Feb 17, 2023 8:27 am
by wilgri
I posted a possible solution to my question here before my thread was approved. Why was my answer deleted?

Re: Merge cells horizontally dynamically

Posted: Fri Feb 17, 2023 10:04 am
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.

Re: Merge cells horizontally dynamically

Posted: Fri Feb 17, 2023 3:40 pm
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.