Using LoadLayout with code-based report

Posted by: softcomlimited on 6 September 2019, 4:20 am EST

    • Post Options:
    • Link

    Posted 6 September 2019, 4:20 am EST

    Hello

    I want to use the LoadLayout function with a code-based report so that the user can customize just the layout but I want my vb.net event code to run instead of any report script that the user might have put. My code will handle things like setting the hyperlink value. I don’t want the user to set a value and get a report for that value, only the app should control that.

    The documentation says “For event related code implementations, it is possible to embed the code in RPX file. In this case, please use Scripting.”

    But that seems to mean that it is either LoadLayout or code-based report but not a combination, am I reading it correctly?

    Regards

    Brian

  • Posted 8 September 2019, 4:51 pm EST

    Hello Brian,

    What I understood from this, you want your customer to only customize the layout of the report.

    You can do the following thing:

    You can give the user the customized EndUserDesginer in which script tab is hidden so that you can’t write their own script.

    Also, you can hide the property grid in the customized EUD so that user can drag-drop the control and changes its size and location only. If you want to hide specific property, then I don’t think so it is possible.

    About RPX and Code-based report, they have the same object structure. You can save/load the Report layout even from/into the Code-based report. What you can do, you can create a code-based report and give user the RPX using the “SaveLayout” method of Code-based report. You can reload the Modified RPX in your code based report.

    However, you need to manually access all the element from the report object added by the user.

    Please correct me, If I am wrong.

    Thanks,

    Mohit

  • Posted 9 September 2019, 1:46 am EST

    Mr Mohitg,

    Yes, I understand the idea to customize the EUD.

    My problem however is that when I Load the layout, the vb.net code in the rptMyReport.vb does not run.

    Simplified, when I run the report, I do the following to get the layout…

    Dim rpt As New GrapeCity.ActiveReports.SectionReport
    rpt = New rptMyReport
    Dim xtr As New System.Xml.XmlTextReader(strReportFilename)
    rpt.LoadLayout(xtr)
    rpt.Document.Name = strReportFilename
    xtr.Close()
    
    

    however the code in the class does not work…

      Private Sub GroupHeader1_Format(sender As Object, e As EventArgs) Handles GroupHeader1.Format
           'bookmark by AcNo 
           Me.GroupHeader1.AddBookmark(Me.txtGLAcNo.Text + " " + Me.txtGLName.Text)
       End Sub
       Private Sub Detail_BeforePrint(sender As Object, e As EventArgs) Handles Detail.BeforePrint
           Me.txtGLTranNo.HyperLink = "rptSingleTrans:" & Me.txtGLTranNo.Text
       End Sub
    
    

    If I don’t do the Load, the code for the hyperlink and bookmarks work correctly.

    Regards

    Brian

  • Posted 9 September 2019, 1:53 am EST

    I forgot to mention that I looked to make sure that there is no script in the rpx that is being loaded.

  • Posted 9 September 2019, 4:47 pm EST

    Hello Brian,

    When you load the layout to report it will ignore all the design time code. That’s why your events don’t fire. You need to add all the event manually like below:

     Dim rpt As New SectionReport1
        Sub New()
    
            ' This call is required by the designer.
            InitializeComponent()
    
            Dim xtr As New System.Xml.XmlTextReader("..\..\Test.rpx")
            ' Dim xtw As New System.Xml.XmlTextWriter("..\..\Test.rpx", System.Text.Encoding.UTF8)
            rpt.LoadLayout(xtr)
            '  rpt.SaveLayout(xtw)
            xtr.Close()
            AddHandler rpt.Sections("GroupHeader1").Format, AddressOf GroupHeader1_Format
            'xtw.Close()
            ' Add any initialization after the InitializeComponent() call.
    
        End Sub
    
        Private Sub GroupHeader1_Format(sender As Object, e As EventArgs)
    
            CType(rpt.Sections("GroupHeader1").Controls("TextBox1"), GrapeCity.ActiveReports.SectionReportModel.TextBox).Text = "test"
        End Sub
    

    I know this will increase your time, but this is the only way to fulfill your requirement.

    I looked to make sure that there is no script in the rpx that is being loaded.

    You can use the following line of code to set the script to blank after loading the report layout.

      rpt.Script = ""
    

    Thanks,

    Mohit

  • Posted 10 September 2019, 2:25 am EST

    Mr Mohit,

    I’m sorry, I really don’t follow where I’m supposed to add the code for the hyperlink and the bookmark. Are there any examples of the technique in the samples ?

    Thanks

    Brian

  • Posted 10 September 2019, 5:42 pm EST

    Hello Brian,

    Please refer the attached sample for implementing the same.

    Thanks,

    Mohit

    Rpt_LoadLayout.zip

  • Posted 11 September 2019, 1:17 pm EST

    Mohit,

    Thanks again. It took me a while to understand what you did and how to fit it into what I have. I did not believe it looked like it would work but it did. Brilliant! You basically make the report class get its events from my other class.

    I have a question though - it is not that it ignores ALL of the code in the report events, just the bits that refer to the textboxes, am I correct? I have code that sets Me.DataSource and also bits changing Me.Detail.BackColor and those still work.

    Thanks a whole lot

    Brian

  • Posted 11 September 2019, 1:49 pm EST

    Mohit,

    There is no way I would have ever worked this out for my self.

    Thanks

    Brian

  • Posted 12 September 2019, 5:24 pm EST

    Hello Brian,

    I have checked at my end and found that they work. However, I would recommend you to set all the properties like(BackColor, DataSource) in the runtime event(as provided in the sample) of the report so that it will not be overridden by any code written in runtime event.

    If you face any problem, please let me know.

    Thanks,

    Mohit

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels