3 Answers, 1 is accepted
Hello George,
Could you please elaborate further on what is meant by dynamically creating reports?
I see it as one of the following two things:
- Creating a report from zero
- Using a report as a template that is then fed with data
Both scenarios are possible, however, we do not recommend designing a report entirely through code, please use the designers instead to create a "base" report and then modify it dynamically with bindings, conditional formatting, etc.
With that being said, if you are keen on doing all the stuff in code, I suggest reading the following articles:
However, if you create the report in the designers, it will be much easier and then you will only need to feed it data - Access Report Items Programmatically | Telerik Reporting.
If you have further questions, please let me know more about your scenario.
Regards,
Dimitar
Progress Telerik
Hi Dimitar and George
I think george has need to create crosstab/Table columns dynamically with respect to his Report Data.
I have also need the same but some issue with the crosstab result . so that I am also question about the same
@george you can also check the sample project attached in the Question
@Dimitar kindly go through the question and if any solution is there let me know
Regards ,
Arun KM
Dear Arun,
I checked your project I am expecting the same thing. Thank you for your valuable replay
Regards ,
George
Hello Dimitar,
I need to print the radgriview data to a report viewer and also i need to customize the column width in report viewer.
Grid 1
Grid 2
These are my 2 grids .I need to print these 2 grid to a common report viewer/common rpt file.my problem is ,using direct grid print method multiple column not fit correctly in the page.
so I need to dynamically customize the column width in report file .
Hello,
Thank you for the images from the grid!
I see the structure of the grid now, however, it is not clear to me whether you have implemented a report(TRDP/TRDX/CS file) with similar a structure.
The grid doesn't get converted to a report automatically, you need to create a report with the same design that you can then feed data to.
Once you have a report, you can set the data either through a data source component or at runtime as shown in the Access Report Items Programmatically article.
The report and its data items have a property named DataSource, this is where the data should be set, either through a data source component wrapper or with the grid initialized data object.
Regarding the size of the columns, you can either design it as you wish in the report template file(TRDX, TRDP, or CS) or you can modify the width through code at runtime - Access report fields from a Table item.
Let me know if you have further questions.
Regards,
Dimitar
Progress Telerik
Hi Dimitar,
Thank you for you replay. But still I cannot find the solution for my problem .
I need to dynamically create the column with respect the data table .Let me know what was the problem in my code . my code is given below
Private Sub Table1_ItemDataBinding(sender As Object, e As EventArgs) Handles ctSupplierPaymentSummary.ItemDataBinding
Try
Dim processingTable As Telerik.Reporting.Processing.Table = (TryCast(sender, Telerik.Reporting.Processing.Table))
Me.ctSupplierPaymentSummary.ColumnGroups.Clear()
Me.ctSupplierPaymentSummary.RowGroups.Clear()
Me.ctSupplierPaymentSummary.Body.Columns.Clear()
Me.ctSupplierPaymentSummary.Body.Rows.Clear()
Dim textboxGroup As Telerik.Reporting.TextBox
Dim tableGroupColumn As Telerik.Reporting.TableGroup
Dim i As Integer = 0
Dim TableGroup2 As Telerik.Reporting.TableGroup = New Telerik.Reporting.TableGroup()
TableGroup2.Groupings.Add(New Telerik.Reporting.Grouping(Nothing))
TableGroup2.Name = "detail"
Me.ctSupplierPaymentSummary.RowGroups.Add(TableGroup2)
For Each dc In mdtResult.Columns
tableGroupColumn = New Telerik.Reporting.TableGroup()
Me.ctSupplierPaymentSummary.Body.Columns.Add(New Telerik.Reporting.TableBodyColumn(Unit.Inch(1)))
textboxGroup = New Telerik.Reporting.TextBox()
textboxGroup.Value = dc.ColumnName.ToString()
textboxGroup.Name = dc.ColumnName.ToString()
textboxGroup.Size = New SizeU(Unit.Inch(1.1), Unit.Inch(0.3))
tableGroupColumn.ReportItem = textboxGroup
ctSupplierPaymentSummary.ColumnGroups.Add(tableGroupColumn)
Dim textBoxTable As Telerik.Reporting.TextBox
textBoxTable = New Telerik.Reporting.TextBox()
textBoxTable.StyleName = "Normal.TableBody"
textBoxTable.Value = "= Fields.[" & dc.ColumnName & "]"
ctSupplierPaymentSummary.Body.SetCellContent(0, i, textBoxTable)
ctSupplierPaymentSummary.Items.AddRange(New ReportItemBase() {textBoxTable, textboxGroup})
i = i + 1
Next
Me.ctSupplierPaymentSummary.DataSource = mdtResult
Catch ex As Exception
Throw ex
End Try
End Sub
This is my Datatable
This is my out put
In output window first column was correct ,but remaining column are wrongI need to print these datatable correctly in .rpt file.This is what I want.
Since you are working with the processing elements, you need to at the end of the ItemDataBinding, set the table data source as follows:
processingTable.DataSource = mdtResult;
If that doesn't work, then the design for the crosstab is probably incorrect. What you may do is the following:
- Take sample data
- Use that data to design the crosstab so that it looks as you expect when you preview the report in the WinForms application
- After you have done that, all you need to do in the data binding event is set the DataSource as suggested above.
The given solution is not not working for me.
can you please correct the sample project attached below
Implementing a custom solution is out of the scope of the support service. This is a very custom scenario that is using an approach that we do not recommend. Designing tables in code should always be avoided because of cases like this one. It is hard to debug the issue and there are better ways to dynamically edit the columns.
Please consider Using Expressions, Conditional Formatting, Bindings, and User Functions instead to dynamically edit a report. These tools are typically the most productive way to build declarative reports and should be favored over using events.
The way the table is right now, it creates a column group for each column. You do not need to do that. All you need to do is to insert a new column for each ColumnName and then get its field data for the row.
If you would need me to give you further suggestions, please send me the data itself, not an image of it, so that I can test it locally.
As we have discussed so far, I will not be able to prepare a custom solution for your needs considering that such case is out of the scope of the support service.
With that being said, going through the following articles should give you a good idea of the possible approaches that you can take:
- How to Create a Dynamic Table/Crosstab/List item (contains a sample report)
- How to add multiple tables dynamically based on the data source (contains a sample report)
- How to modify table with preset styles and width dynamically
Such a custom scenario is not in the scope of the support service. With that being said, through the linked resources in previous replies, you should be able to achieve the desired result but as said earlier, it will be a much easier process if you use the Visual Studio Report Designer to design the crosstab and to then only feed it data.