Dynamic Report Creation

3 Answers 148 Views
GridView
George
Top achievements
Rank 1
Iron
George asked on 23 Aug 2022, 03:06 AM
How to create dynamic report from Radgridview and how to customize the column width dynamically in report viewer?

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 25 Aug 2022, 11:40 AM

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

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
Arun
Top achievements
Rank 1
Iron
commented on 26 Aug 2022, 05:20 AM

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 

Dynamic Colum Creation 

@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

George
Top achievements
Rank 1
Iron
commented on 26 Aug 2022, 07:27 AM

Dear Arun,

I checked your project I am expecting the same thing. Thank you for your valuable replay

Regards ,

George

0
George
Top achievements
Rank 1
Iron
answered on 25 Aug 2022, 01:40 PM

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 .

0
Dimitar
Telerik team
answered on 30 Aug 2022, 07:52 AM

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

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
George
Top achievements
Rank 1
Iron
commented on 30 Aug 2022, 11:17 AM

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.

Dimitar
Telerik team
commented on 01 Sep 2022, 07:24 AM

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:

  1. Take sample data
  2. Use that data to design the crosstab so that it looks as you expect when you preview the report in the WinForms application
  3. After you have done that, all you need to do in the data binding event is set the DataSource as suggested above.
George
Top achievements
Rank 1
Iron
commented on 01 Sep 2022, 09:44 AM

The given solution is not not working for me.

can you please correct the sample project attached below

Dimitar
Telerik team
commented on 06 Sep 2022, 03:18 PM

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 ExpressionsConditional FormattingBindings, 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.

    George
    Top achievements
    Rank 1
    Iron
    commented on 07 Sep 2022, 07:25 AM

    Here I am attaching my demo project. I need to create cross tab according to my data table dynamically.
    Dimitar
    Telerik team
    commented on 12 Sep 2022, 08:44 AM

    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:

    George
    Top achievements
    Rank 1
    Iron
    commented on 13 Sep 2022, 02:34 PM

    How can i create dynamic report without design report cross tab columns. Can you please provide a demo project?
    Dimitar
    Telerik team
    commented on 16 Sep 2022, 07:26 AM

    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.

    Tags
    GridView
    Asked by
    George
    Top achievements
    Rank 1
    Iron
    Answers by
    Dimitar
    Telerik team
    George
    Top achievements
    Rank 1
    Iron
    Share this question
    or