This is a migrated thread and some comments may be shown as answers.

I can not create a new TextBox in method detail_ItemDataBinding at the first row

4 Answers 242 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Lucio
Top achievements
Rank 1
Lucio asked on 13 Mar 2018, 06:23 PM

Could you tell me why when I create a new text box in the "detail_ItemDataBinding" method (for each row) ... this new text box is only created in the second row (and in the third row, and in fourth ... but never in the first) ...? I can not create any new text boxes in the first row ... It's the same code for each row

Why it happens?

Thanks

4 Answers, 1 is accepted

Sort by
0
Silviya
Telerik team
answered on 16 Mar 2018, 02:50 PM
Hi Lucio,

Generally we don't encourage our users to create Telerik Reporting reports programmatically. We do not recommend also the report event handlers (as ItemDataBinding) to be used for modifying report definition.

It is not allowed to add new items in an event because it might cause side effects. Like in this case, the item is added from the second rendering of the Detail section:
private void detail_ItemDataBinding(object sender, EventArgs e)
{
    Telerik.Reporting.Processing.DetailSection detail = (sender as Telerik.Reporting.Processing.DetailSection);
    Telerik.Reporting.TextBox test = new Telerik.Reporting.TextBox();
 
    test.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Inch(0D), Telerik.Reporting.Drawing.Unit.Inch(3.9418537198798731E-05D));
    test.Name = "test";
    test.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(2.2000000476837158D), Telerik.Reporting.Drawing.Unit.Inch(0.19996055960655212D));
    test.Style.BorderStyle.Default = Telerik.Reporting.Drawing.BorderType.Solid;
    test.Value = "= Fields.test";
    detail.ItemDefinition.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { test });
}

Our recommendation is to create a TextBox item design-time and set it's properties on ItemDataBinding event:
private void detail_ItemDataBinding(object sender, EventArgs e)
{
    Telerik.Reporting.Processing.DetailSection section = (sender as Telerik.Reporting.Processing.DetailSection);
    Telerik.Reporting.Processing.TextBox txt = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.GetChildByName(section, "test");
 
    txt.Value = "= Fields.test";
}

For more information, please refer to these help articles:
Report Events: Using Section Events
Report Events: Understanding Events

If you need further help, send us the report files, test data and details about the expected behavior in a support ticket.

Regards,
Silviya
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Lucio
Top achievements
Rank 1
answered on 02 Apr 2018, 04:32 PM
Thanks for answering. The problem is I have to create textboxes dynamically, because I have to form an Organization chart. And this Organization chart could be diferente any time. So I have to create them at run time.

If a use the "detail_ItemDataBound" event instead of... I can do it... But.. It seems the first row "jumps" to the second one and so... Is there any "bug" in telerik events?
0
Lucio
Top achievements
Rank 1
answered on 02 Apr 2018, 04:34 PM

Mistake: "If a use" = "If I use"...Sorry :-)

 

0
Silviya
Telerik team
answered on 05 Apr 2018, 12:42 PM
Hello Lucio,

In general, reports are data-driven which allows you to change an item's settings via conditional formatting, bindings and expression used as Value property, all based on the data fields.

So, my recommendation is to create TextBox items design-time, then modify their properties on ItemDataBinding event and use conditional formatting or binding rule to conditionally hide them. In case you have a complex requirement to show/hide data, you could create an user function that allow you to extend the default behavior of the Telerik Reporting engine.

As a side note, more considerations on this topic are provided in Modifying or Creating a report at Run-Time KB article.

Back to your question regarding the incorrect behavior of events, we would need to check the code of event handlers in order to provide you further suggestion. You can share it here or in a new support ticket.

Regards,
Silviya
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Lucio
Top achievements
Rank 1
Answers by
Silviya
Telerik team
Lucio
Top achievements
Rank 1
Share this question
or