Create dynamic textbox

7 posts, 0 answers
  1. Rahul Khinvasara
    Rahul Khinvasara avatar
    303 posts
    Member since:
    Aug 2007

    Posted 29 Nov 2007 Link to this post

    Hi,
          I want to create textboxes dynamically at runtime.In my application the number of columns returned from database is not fixed. So I have to create that number of textboxes as the number of column returned.
          For that I have used the following code:

            Dim cntColumns As Integer
            cntColumns = ds.Tables(0).Columns.Count()-1
            Dim xaxis, yaxis As Integer
            Dim headcolumnname As String
            Dim i As Integer
            Dim headcolumnlist As Telerik.Reporting.ReportItemBase() = New          Telerik.Reporting.ReportItemBase(cntColumns) {}
            For i = 0 To cntColumns
                headcolumnname = ds.Tables(0).Columns(i).ColumnName
                headcolumnlist(i) = CreatetxtHead(headcolumnname, i)
                Dim textBox As Telerik.Reporting.TextBox =               DirectCast(headcolumnlist(i), TextBox)
                textBox.Location = New Telerik.Reporting.Drawing.PointU(New               Telerik.Reporting.Drawing.Unit(xaxis,               Telerik.Reporting.Drawing.UnitType.Inch), New               Telerik.Reporting.Drawing.Unit(yaxis,               Telerik.Reporting.Drawing.UnitType.Inch))
           textBox.Size = New SizeU(New Unit(2,     Telerik.Reporting.Drawing.UnitType.Cm), New     Telerik.Reporting.Drawing.Unit(2,     Telerik.Reporting.Drawing.UnitType.Cm))
              i += 1
              xaxis += 1
            Next
            Me.ReportHeaderSection1.Items.AddRange(headcolumnlist)
            Me.Items.Add(DirectCast(ReportHeaderSection1, ReportItemBase))


    Private Function CreatetxtHead(ByVal FieldName As String, ByVal i As Integer) As Telerik.Reporting.TextBox
            Dim txtHead As New Telerik.Reporting.TextBox()
            txtHead.Value = "=[" + FieldName + "]"
            Return txtHead
        End Function

    When I execute this code I am getting error 'value must be of type Telerik.Reporting.ReportItemBase' at the Me.ReportHeaderSection1.Items.AddRange(headcolumnlist) location.
             This code sample I have taken from forum. Can you please help me what error I am making?

    Thanks,
    Rahul
  2. Milen
    Admin
    Milen avatar
    163 posts

    Posted 29 Nov 2007 Link to this post

    Hi Rahul Khinvasara,

    I am glad to write you again.

    As you know, the telerik report is a .NET class as any other, so you can instantiate a object of that class as of any other class and then set its properties. Actually, the report designer does nothing more then creating items and setting properties for you. So, the best way to learn how to create a report programmatically is to use the designer to create a report and then look at the code generated by the designer.

    Lets review the code you send to us. Actually it is almost working.

    Dim cntColumns As Integer
            cntColumns = ds.Tables(0).Columns.Count()-1
            Dim xaxis, yaxis As Integer
            Dim headcolumnname As String
            Dim i As Integer
            Dim headcolumnlist As Telerik.Reporting.ReportItemBase() = New          Telerik.Reporting.ReportItemBase(cntColumns) {}
            For i = 0 To cntColumns
                headcolumnname = ds.Tables(0).Columns(i).ColumnName
                headcolumnlist(i) = CreatetxtHead(headcolumnname, i)
                Dim textBox As Telerik.Reporting.TextBox =               DirectCast(headcolumnlist(i), TextBox)
                textBox.Location = New Telerik.Reporting.Drawing.PointU(New               Telerik.Reporting.Drawing.Unit(xaxis,               Telerik.Reporting.Drawing.UnitType.Inch), New               Telerik.Reporting.Drawing.Unit(yaxis,               Telerik.Reporting.Drawing.UnitType.Inch))
           textBox.Size = New SizeU(New Unit(2,     Telerik.Reporting.Drawing.UnitType.Cm), New     Telerik.Reporting.Drawing.Unit(2,     Telerik.Reporting.Drawing.UnitType.Cm))

              i += 1 'This statement is  redundant as the for cycle increases i on each turn, this causes the exception you described
              xaxis += 1
            Next
            Me.ReportHeaderSection1.Items.AddRange(headcolumnlist) 'this statement adds the generated textboxes to the ReportHeader section, and you should add them to the DetailSection, because their values are expressions that pull the data from the rows of the dataset
            Me.Items.Add(DirectCast(ReportHeaderSection1, ReportItemBase))


    Private Function CreatetxtHead(ByVal FieldName As String, ByVal i As Integer) As Telerik.Reporting.TextBox
            Dim txtHead As New Telerik.Reporting.TextBox()
            txtHead.Value = "=[" + FieldName + "]"
            Return txtHead
        End Function


    In the attached project you can review a working sample of your scenario.

    I hope this information helps.

    Best wishes,
    Milen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. DevCraft banner
  4. Rahul Khinvasara
    Rahul Khinvasara avatar
    303 posts
    Member since:
    Aug 2007

    Posted 30 Nov 2007 Link to this post

    Hi,
        It got worked! Thanks a lot!
        I really appreciate the instant reply from your team!!!It is helping me a lot
    Thanks,
    Rahul
       
  5. Jakub Gutkowski
    Jakub  Gutkowski  avatar
    5 posts
    Member since:
    Nov 2008

    Posted 21 Dec 2008 Link to this post

    Thanks :) that was exaclty what I was looking for :)

    Cheers,
       Jakub G
  6. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 04 Mar 2009 Link to this post

    Hi guys,

    I'm attaching C# version of the project, since an user had problems with the conversion.

    Kind regards,
    Steve
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Rajiv
    Rajiv avatar
    4 posts
    Member since:
    Jul 2014

    Posted 07 Aug 2014 in reply to Steve Link to this post

    I cannot find telerik.reporting.interfaces and telerik.reporting.processing in the project.. nor anywhere on my computer.. 
  8. Stef
    Admin
    Stef avatar
    3047 posts

    Posted 11 Aug 2014 Link to this post

    Hi Rajiv,

    This is an old thread. The recommended approach to dynamically create reports is to start with the integrated in Visual Studio report designer. Thus you can get acquainted with the report and items' structure, and reuse and modify the code generated in the test report's designer.cs(vb) file. Following the described approach will show you the required assemblies as well.

    Regards,
    Stef
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
DevCraft banner