Page 1 of 1

Programically Component attachment

Posted: Sat Sep 04, 2010 8:22 am
by uday
Let me know, how can i attach a component through code.

Like I have a report file whose name is Report.mrt, who has a databind and the databind contains two text box one for Name and another for city,
Now I want to add another text box through coding for Phone.
Note that the data source consist all filed [Name, City, Phone, etc.]

Please give me an example.

Programically Component attachment

Posted: Mon Sep 06, 2010 1:38 am
by Alex K.
Hello,

You can use the following code:

Code: Select all

StiReport report = new StiReport();
report.Load(@"D:\Sample report.mrt");
StiDataBand dataBand = report.GetComponents()["DataBand1"] as StiDataBand;
StiText textComponentAdd = new StiText();
textComponentAdd.Height = 1;
textComponentAdd.Width = 1;
textComponentAdd.Left = 10;
textComponentAdd.Name = "TextPhone";
textComponentAdd.Text = "{DataSource.Phone}";
textComponentAdd.Parent = dataBand;
dataBand.Components.Add(textComponentAdd);
Thank you.