Page 1 of 1
Set DataBand DataSource at Runtime
Posted: Mon Dec 08, 2025 3:42 pm
by admin@secsol.co.uk
Is there anyway to change the DataSource for a DataBand at runtime - during the report production.
I tried using :
Code: Select all
If (Info.DatabaseSelected == 1)
HeaderDataBand,DataSource = FavouriteHeaderMechanical
Where Info is a business object.
Basically I want one report to work for either database and be selected by a value in a business object. Is this possible?
Re: Set DataBand DataSource at Runtime
Posted: Mon Dec 08, 2025 4:32 pm
by Lech Kulikowski
Hello,
You can use the following code:
var databand = report.GetComponentByName("DataBand1") as StiDataBand;
databand.DataSourceName = "DataSourceName";
Thank you.
Re: Set DataBand DataSource at Runtime
Posted: Mon Dec 15, 2025 8:10 am
by admin@secsol.co.uk
Thanks for that.
How do I change the field within the databand to pick up the new data source?
i.e. in the field above it is picking up FavouriteHeaderElectrical.MainDescription - I tried changing it to be dataField.Text = FavouriteHeaderMechanical.MainDescription but it still used the old data source.
Is there any way to set a data field to automatically just use the databand data source i.e. dataField.Text = dataBand.DataSource.MainDescription?
Re: Set DataBand DataSource at Runtime
Posted: Mon Dec 15, 2025 8:46 pm
by Lech Kulikowski
Hello,
Unfortunately, no. You should change the expression; there are no automatic methods.
Thank you.