Change cell's margin with conditions

Stimulsoft Reports.NET discussion
Post Reply
lsilva.gvdasa
Posts: 25
Joined: Tue Apr 11, 2017 4:47 pm

Change cell's margin with conditions

Post by lsilva.gvdasa »

Hello,

I'm using the table component and need to apply some manipulation on cell's margin according to a condition.

I'm trying something like:

if (varCont == 4) {
CellName.Margins.Left = 20;
} else {
CellName.Margins.Left = 0;
}

But it seems like the component picks up the last value setted for left on CellName for all occurrences of this cell in the rows appeared in the table.

Thanks.

Is it possible to change the CellName's properties for each row appeared?
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Change cell's margin with conditions

Post by HighAley »

Hello.

The Table component is created to simplifuy the creation of reports.
At the rendering time this component is converted to Header, Footer and Data Bands.
Please, try to replace the table component with these components. They are more flexible.

Thank you.
lsilva.gvdasa
Posts: 25
Joined: Tue Apr 11, 2017 4:47 pm

Re: Change cell's margin with conditions

Post by lsilva.gvdasa »

HighAley wrote:Hello.

The Table component is created to simplifuy the creation of reports.
At the rendering time this component is converted to Header, Footer and Data Bands.
Please, try to replace the table component with these components. They are more flexible.

Thank you.
Hello!

I'm changing right now to data bands with text components inside, but it seems like I can't change the text margin with conditions. Is there any limitations about it?
Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

Re: Change cell's margin with conditions

Post by Ivan »

Hello,
But it seems like the component picks up the last value setted for left on CellName for all occurrences of this cell in the rows appeared in the table.
It's a memory optimization: when a clone of the base component is created, properties that rarely change, are not cloned but copied.
So all instances of a base component have in Margins the same object (not the clone).
If you want to modify margins, you need to create a new object, for example:

Code: Select all

if (varCont == 4) {
CellName.Margins = new Stimulsoft.Report.Components.StiMargins(20, 0, 0, 0);
} else {
CellName.Margins. = new Stimulsoft.Report.Components.StiMargins(0, 0, 0, 0);
}
Thank you.
User avatar
tpontow
Posts: 206
Joined: Thu Sep 06, 2012 8:46 am
Location: Bonn, Germany

Re: Change cell's margin with conditions

Post by tpontow »

Sorry, but it's not working.

I tried to set a different margin (10 instead of 5) for a text component only on second line. But it does not work. All lines are affected.

Code: Select all

if (Line == 2)DataTabelle1_Konto.Margins = new Stimulsoft.Report.Components.StiMargins(20,0,0,0);
else DataTabelle1_Konto.Margins = new Stimulsoft.Report.Components.StiMargins(5,0,0,0);
Take any sample Report and set that above code to BeforePrint-Event of any text component you like. It's not working. You cannot change margin for only one row.

Thanks
Thorsten Pontow
Thorsten Pontow

It is easier to write an incorrect program than to understand a correct one. (Alan J. Perlis, Epigrams in programming No. 7)
Lech Kulikowski
Posts: 6198
Joined: Tue Mar 20, 2018 5:34 am

Re: Change cell's margin with conditions

Post by Lech Kulikowski »

Hello,

Please send us a sample report with test data which reproduces the issue for analysis.

Thank you.
User avatar
tpontow
Posts: 206
Joined: Thu Sep 06, 2012 8:46 am
Location: Bonn, Germany

Re: Change cell's margin with conditions

Post by tpontow »

Take any sample Report and set that above code to BeforePrint-Event of any text component you like.
Thorsten Pontow

It is easier to write an incorrect program than to understand a correct one. (Alan J. Perlis, Epigrams in programming No. 7)
Lech Kulikowski
Posts: 6198
Joined: Tue Mar 20, 2018 5:34 am

Re: Change cell's margin with conditions

Post by Lech Kulikowski »

Hello,

Please check the following code:

Code: Select all

Text1.Properties = Text1.Properties.Clone() as Stimulsoft.Base.StiRepositoryItems;
if (Line > 3) Text1.Margins = new Stimulsoft.Report.Components.StiMargins(20, 0, 0, 0);
else Text1.Margins = new Stimulsoft.Report.Components.StiMargins(0, 0, 0, 0);
Thank you.
User avatar
tpontow
Posts: 206
Joined: Thu Sep 06, 2012 8:46 am
Location: Bonn, Germany

Re: Change cell's margin with conditions

Post by tpontow »

Hi Lech,

that solution works. Great! Thanks for your kind help and support.

Best regards
Thorsten Pontow
Thorsten Pontow

It is easier to write an incorrect program than to understand a correct one. (Alan J. Perlis, Epigrams in programming No. 7)
Lech Kulikowski
Posts: 6198
Joined: Tue Mar 20, 2018 5:34 am

Re: Change cell's margin with conditions

Post by Lech Kulikowski »

Hello

We are always glad to help you!
Do not hesitate to contact us in case of further questions.

Thank you.
Post Reply