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

Formatting Report Items at ItemDataBining

1 Answer 41 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Lorenzo
Top achievements
Rank 1
Lorenzo asked on 09 Feb 2010, 06:34 PM
Hi all,
I'm facing a huge difficulty trying to get a Report formatting certain items at ItemDataBinding.
My idea would be to build a "general purpose" report able to show informations from a DataSource and displaying each item of those datas in tow possible different ways:
  1. As a Label + TextBox
  2. As a Label + CheckBox

My DataSource looks like:
Private Sub Report_NeedDataSource(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.NeedDataSource 
        Dim oRowList As New List(Of MyDataRow) 
        oRowList.Add(New MyDataRow("Sezione 1", 1, "Nome del candidato""Mario")) 
        oRowList.Add(New MyDataRow("Sezione 1", 1, "Cognome del candidato""Rossi")) 
        oRowList.Add(New MyDataRow("Sezione 1", 1, "Data di nascita""20/05/1960")) 
        oRowList.Add(New MyDataRow("Sezione 2", 1, "Indirizzo""Via Milano, 18")) 
        oRowList.Add(New MyDataRow("Sezione 2", 1, "Cap""20100")) 
        oRowList.Add(New MyDataRow("Sezione 2", 1, "Città""Milano")) 
        oRowList.Add(New MyDataRow("Sezione 2", 1, "Provincia""MI")) 
        oRowList.Add(New MyDataRow("Sezione 3", 1, "Animale preferito""")) 
        oRowList.Add(New MyDataRow("Sezione 3", 2, "Gatto""X")) 
        oRowList.Add(New MyDataRow("Sezione 3", 2, "Cane""")) 
        oRowList.Add(New MyDataRow("Sezione 3", 2, "Pappagallo""X")) 
 
 
        CType(sender, Telerik.Reporting.Processing.Report).DataSource = oRowList 
 
    End Sub 
...and as you can see I'm binding it to the report at the NeedDataSource Event.

 The Class MyDataRow contains:
  • Group Field
  • Type field
  • Label field
  • Text field
Although this is a static reprsentation of my DataBase  it is well functional to my explanation.
My Report Contains a Grouping, based on the "Group" field, and two TextBox bounded to the Label field and to the Text field of my MyDataRow. If I run the Report I can see all my datas correctly bounded.
The problem raises when I try to intervene on formatting of the two TextBox fields at DataBinding. Code follows:
Private Sub DetailSection1_ItemDataBinding(ByVal sender As ObjectByVal e As System.EventArgs) Handles DetailSection1.ItemDataBinding 
        Dim ProcessingDetail As Telerik.Reporting.Processing.DetailSection = CType(sender, Telerik.Reporting.Processing.DetailSection) 
        Dim oDataRow As MyDataRow = CType(ProcessingDetail.DataObject.RawData, MyDataRow) 
 
        If oDataRow.Type = 2 Then 
 
            T_Label.Size = New SizeU(New Unit(18, UnitType.Cm), New Unit(0.5, UnitType.Cm)) 
            T_Label.Location = New PointU(New Unit(1, UnitType.Cm), New Unit(0, UnitType.Cm)) 
 
            T_Text.Style.BorderColor.Default = Color.Black 
            T_Text.Style.BorderStyle.Default = BorderType.Solid 
            T_Text.Style.BorderWidth.Default = New Unit(2, UnitType.Point) 
            T_Text.Size = New SizeU(New Unit(0.5, UnitType.Cm), New Unit(0.5, UnitType.Cm)) 
            T_Text.Location = New PointU(New Unit(0, UnitType.Cm), New Unit(0, UnitType.Cm)) 
            T_Text.Style.TextAlign = HorizontalAlign.Center 
            T_Text.Style.Font.Bold = True 
 
        End If 
    End Sub 

As you ca see, if the Type field of my Datasource is "2" what I do is format my two TextBoxes in such a way that they look like a CheckBox and a label following. HERE RAISES THE PROBLEM !
What comes out of my report is that the formatting gets applied only after the first "Record" of my data source has been parsed. Attached You'll find a screen shot of what happens when I get to bind the part of the data source containing Records of type "2".

I'm relatively new to programming and especially with Telerik components, so I might have posted a "stupid" problem, but I'm going nuts.
Thanks for any help provided.

Lorenzo

1 Answer, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 10 Feb 2010, 05:59 PM
Hello Lorenzo,

This is a common mistake when trying to alter a report item through code. As the Report Life Cycle topic explains the Telerik Reporting engine works with two object:
  • the report definition - "the Report" - is  a class derived from Telerik.Reporting.Report; usually created with the help of the Report Designer or programmatically. Its only purpose is to describe how the report will look like. You may think of the reports as data grids - when you put the data grid on a form, this is actually the description/template of the grid which defines how the data will be displayed, appearance and behavior. This is exactly what the report definition is for. (Although it is a .NET class now, we have plans to move it to the simpler XML description)
  • the report instance (an object type Telerik.Reporting.Processing.Report) is the report definition merged with the data from the data source.
Both objects look similar (and sometimes both are called "Reports", which is incorrect), but are not the same as you can guess from their namespaces.
You can find more info about the report definition and report processing objects in Understanding Events help topic.
In short, you should get reference to the processing textbox objects and apply the changes to them, just like you set the DataSource to the processing report.

All the best,
Steve
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
General Discussions
Asked by
Lorenzo
Top achievements
Rank 1
Answers by
Steve
Telerik team
Share this question
or