How to change width of text controls in a data band at runtime?

Stimulsoft Reports.NET discussion
Post Reply
haarrrgh
Posts: 13
Joined: Wed Apr 14, 2010 8:10 am

How to change width of text controls in a data band at runtime?

Post by haarrrgh »

Hi,

I need help with conditional formatting.
I have a report with a data band. The data band contains several text controls per row, for example like this:

Code: Select all

|  Field 1  |  Field 2  |  Field 3  |  Field 4  |
Now I need to do the following:
depending on a value in the data source, I need to change the width of some fields in some rows.

For example, if the datasource has 20 rows and the special value in row 14 says "make Field 2 wider", then I want to change the fields only in this row, so they look like that:

Code: Select all

|  Field 1  |  Field 2              |  Field 4  |
--> Field 2 is wider than before and Field 3 is disabled in order to make room for Field 2.

The other rows should stay as they are (so they still look like the first example).

There are different possibilities which field has to become wider and which field(s) have to be disabled in order to make room for the wider field, and they can all occur in the same report.


I know how to edit "normal" controls in a designer generated report at runtime, but I don't know how to iterate through each row of a data band.
Or is this somehow possible via conditions?

Thank you!
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

How to change width of text controls in a data band at runtime?

Post by Jan »

Hello,

Please check attached report. This report from Demo.exe application. It use internal dialog form for report settings, but you can use other report logic.

Thank you.
Attachments
399.SelectingColumns.mrt
(36.93 KiB) Downloaded 265 times
haarrrgh
Posts: 13
Joined: Wed Apr 14, 2010 8:10 am

How to change width of text controls in a data band at runtime?

Post by haarrrgh »

Hi Jan,

thank you for your answer, but I'm afraid that's not what I wanted.

You mean this code in the form, right?

Code: Select all

foreach (StiComponent comp in DataBand1.Components)
{
	if (comp.Enabled)width += comp.Width;    
}
That loops through the columns and makes changes to the width of the text boxes, but the width is the same in each row.


What I want instead is to change the width only for some special rows.

An example:

Let's say that the databand contains this at design time:

Code: Select all

-------------------------------------------------
|  Field 1  |  Field 2  |  Field 3  |  Field 4  |
-------------------------------------------------
At runtime, I want to change it so it looks like this:

Code: Select all

     -------------------------------------------------
1.   |  Field 1  |  Field 2  |  Field 3  |  Field 4  |
     -------------------------------------------------
2.   |  Field 1  |  Field 2  |  Field 3  |  Field 4  |
     -------------------------------------------------
3.   |  Field 1  |  Field 2 (wider)      |  Field 4  |
     -------------------------------------------------
4.   |  Field 1  |  Field 2  |  Field 3  |  Field 4  |
     -------------------------------------------------
5.   |  Field 1  |  Field 2  |  Field 3 (wider)      |
     -------------------------------------------------
In row 3, Field 2 is wider and Field 3 is invisible to make room for Field 2.
In row 5, Field 3 is wider and Field 4 is invisible to make room for Field 3.

In all the other rows, nothing has changed.


How can I do this?
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

How to change width of text controls in a data band at runtime?

Post by Jan »

Hello,

You can use some scripts in BeforePrintEvent of DataBand. Something like this:

Code: Select all

TextComp1.Enabled = condition1;
TextComp2.Enabled = condition2;
TextComp3.Enabled = condition3;
TextComp4.Enabled = condition4;
if (!TextComp2.Enabled)TextComp1.Width += TextComp2.Width;

...

Thank you.
Post Reply