build Subreport by " Vb.net " code in Run Time ??

Stimulsoft Ultimate discussion
Post Reply
Eng.MAMB
Posts: 14
Joined: Mon May 23, 2011 1:44 am
Location: K.S.A

build Subreport by " Vb.net " code in Run Time ??

Post by Eng.MAMB »

hi everyone

I have question , And I hope Found Answer on it soon ,,

Q: How I Can build Subreport by " Vb.net " code and Insert it on Report Before Show it in "Stiviower Control" in Run Time ??


I try write these Code

Code: Select all

Private Function ViewReport(ByVal RptID As Integer) As Boolean
        Try
            Dim dtRpt As New DataTable
            Dim dsRptDesigner As New DataSet
            Dim cmd As New Data.SqlClient.SqlCommand
            Dim da As New Data.SqlClient.SqlDataAdapter
            Dim ds As New DataSet
            Dim mRptName, mRptPath, mRptDataPath As String

			'Load Strem Report
            StiReport1.Load(clsDesign.ConvertToStreem(mBayt))
            clsDesign.ConvertToPath(mBayt)

            
                StiReport1.Dictionary.Databases.Clear()
                StiReport1.Dictionary.DataSources.Clear()

                StiReport1.RegData(ds)
                StiReport1.Dictionary.Synchronize()
                




			'Creat Subreport
            If dtRpt.Rows(0).Item("WithoutHead") = False Then
                Dim HheaderRpt As New Stimulsoft.Report.StiReport
                HheaderRpt.Load("C:\mReport.mrt")

                StiReport1.SubReports.Add(HheaderRpt)
                Dim SubReport1 As New Stimulsoft.Report.Components.StiSubReport
                SubReport1.Report = HheaderRpt

                StiReport1.Pages.Items(0).Components.AddRange(New Stimulsoft.Report.Components.StiComponent() {SubReport1})
            End If
            StiViewer.Report = StiReport1
            StiViewer.Show()
            StiReport1.Render()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Function
But it is Not Working !! :tire:
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

build Subreport by " Vb.net " code in Run Time ??

Post by Alex K. »

Hello,

Please see the sample project in attachment.

Thank you.
Attachments
1031.SampleProjectVB.zip
(23.27 KiB) Downloaded 507 times
Eng.MAMB
Posts: 14
Joined: Mon May 23, 2011 1:44 am
Location: K.S.A

build Subreport by " Vb.net " code in Run Time ??

Post by Eng.MAMB »

Thank you Mr.Aleksey Kulikovsky for reply on me
:biggrin:


when I make same code in my Project
is work :)
but the data inside subreport not view :(
:hugging:

it is view only empty Page !!
note: subreport is connection to another Dictionary And datasource
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

build Subreport by " Vb.net " code in Run Time ??

Post by Alex K. »

Hello,

Please send us your project with sample data for amalysis on support@stimulsoft.com.

Thank you.
Eng.MAMB
Posts: 14
Joined: Mon May 23, 2011 1:44 am
Location: K.S.A

build Subreport by " Vb.net " code in Run Time ??

Post by Eng.MAMB »

Thank very much for you .. Again ,,,. Mr.Aleksey Kulikovsky for reply on me
:blush:

I solved The Problem in Above
But ,, now I need to Add More Than Sub Report
In your Answer in Above
you was writ this Code
------

Code: Select all

Private Sub report_GetSubReport(ByVal sender As Object, ByVal e As StiGetSubReportEventArgs)
        Dim subReport As StiReport = New StiReport()
        subReport.Load("e:\SubReport.mrt")
        e.Report = subReport
    End Sub
----

Now How I can Add More Than Sub Report in run time ?
:ops:
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

build Subreport by " Vb.net " code in Run Time ??

Post by Alex K. »

Hello,

As a way, you can use the following code:

Code: Select all

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Try
        Dim WithSubReport As Boolean = True

        Dim report As StiReport = New StiReport
        report.Load("Report.mrt")

        'Creat Subreport 
        If WithSubReport Then
            'SubReport1
            Dim SubReport1 As Stimulsoft.Report.Components.StiSubReport = New Stimulsoft.Report.Components.StiSubReport()
            SubReport1.ClientRectangle = New Stimulsoft.Base.Drawing.RectangleD(1.6, 1.2, 15.6, 3.2)
            SubReport1.Name = "SubReport1"
            SubReport1.UseExternalReport = True
            report.Pages(0).Components.AddRange(New Stimulsoft.Report.Components.StiComponent() {SubReport1})
            AddHandler report.GetSubReport, AddressOf report_GetSubReport

            'SubReport2
            Dim SubReport2 As Stimulsoft.Report.Components.StiSubReport = New Stimulsoft.Report.Components.StiSubReport()
            SubReport2.ClientRectangle = New Stimulsoft.Base.Drawing.RectangleD(1.6, 5.4, 15.6, 3.2)
            SubReport2.Name = "SubReport2"
            SubReport2.UseExternalReport = True
            report.Pages(0).Components.AddRange(New Stimulsoft.Report.Components.StiComponent() {SubReport2})

            'SubReport3
            Dim SubReport3 As Stimulsoft.Report.Components.StiSubReport = New Stimulsoft.Report.Components.StiSubReport()
            SubReport3.ClientRectangle = New Stimulsoft.Base.Drawing.RectangleD(1.6, 9.6, 15.6, 3.2)
            SubReport3.Name = "SubReport3"
            SubReport3.UseExternalReport = True
            report.Pages(0).Components.AddRange(New Stimulsoft.Report.Components.StiComponent() {SubReport3})
        End If

        report.Render()
        report.Design()
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Sub

Private Sub report_GetSubReport(ByVal sender As Object, ByVal e As StiGetSubReportEventArgs)
    Dim subReport As StiReport = New StiReport()

    If e.SubReportName = "SubReport1" Then
        subReport.Load("SubReport1.mrt")
    End If
    If e.SubReportName = "SubReport2" Then
        subReport.Load("SubReport2.mrt")
    End If
    If e.SubReportName = "SubReport3" Then
        subReport.Load("SubReport3.mrt")
    End If

    e.Report = subReport
End Sub
Thank you.
Eng.MAMB
Posts: 14
Joined: Mon May 23, 2011 1:44 am
Location: K.S.A

build Subreport by " Vb.net " code in Run Time ??

Post by Eng.MAMB »

:blush:

Thank You Mr.Aleksey
Andrew
Posts: 4107
Joined: Fri Jun 09, 2006 3:58 am

build Subreport by " Vb.net " code in Run Time ??

Post by Andrew »

As always we are glad to help you!
Post Reply