Creating reports and dashboards | Stimulsoft community forum
Reporting tool and data analytics tools for creating reports and dashboards in ASP.NET, ASP.NET MVC, .NET Core, Blazor, Angular, PHP, Python, WPF, JavaScript, and Java applications.
Dim rp as New StiReport()
Dim eV As New Stimulsoft.Report.Events.StiEndRenderEvent
eV.Script = "For Each d As Stimulsoft.Report.Dictionary.StiDataSource In Me.DataSources" & vbCrLf & "MessageBox.Show(d.Name)" & vbCrLf & "MessageBox.Show(d.Rows.Count)" & vbCrLf & "Next"
rp.EndRenderEvent = eV
rp.Render(true)
rp.Show(true)
As AddHandler doesn't seem to work for rp.EndRender !!
I need to add a function to the report's end render event, so that I can adjust the dataset before it is being outputed onto the preview control....
Yes, the simpler method exists. In your case you are modify a script of the report. But also you may add own Event Handler for the report.CompiledReport.EndRender event. But the assigned may be proceed after compiling of the report. The order of your steps should be the following:
report.Compile()
AddHandler report.CompiledReport.EndRender, New EventHandler(AddressOf MyReport_EndRender)
report.PreviewControl = StiPreviewControl1
report.Show()
Private Sub MyReport_EndRender(ByVal sender As Object, ByVal e As System.EventArgs)
For Each d As Stimulsoft.Report.Dictionary.StiDataSource In sender.DataSources
If d.Rows.Count = 0 Then
MessageBox.Show("There are no records")
End If
Next
End Sub
It reaches MyReport_EndRender function fine and it executes the code, but when it reaches MessageBox.Show("There are no records"), nothing pops up - not even the preview control....
jing wrote:It reaches MyReport_EndRender function fine and it executes the code, but when it reaches MessageBox.Show("There are no records"), nothing pops up - not even the preview control....
tells to report that report.Show() method will not show a report preview in the separate window. After that the rendered report will be shown in the StiPreviewControl only. So you need to show the form with StiPreviewControl on it before calling the Show method.
report.Compile()
AddHandler report.CompiledReport.EndRender, New EventHandler(AddressOf MyReport_EndRender)
report.PreviewControl = StiPreviewControl1
report.Show(True)
Private Sub MyReport_EndRender(ByVal sender As Object, ByVal e As System.EventArgs)
For Each d As Stimulsoft.Report.Dictionary.StiDataSource In sender.DataSources
If d.Rows.Count = 0 Then
MessageBox.Show("There are no records")
End If
Next
End Sub
Still the MessageBox.Show("There are no records") does not show up !!!
Maybe I am doing this wrong and there is an easier method.
What I want to do is to display a message whenever there are no records before the report is displayed on a Preview Control. What will be the easiest way of doing this? - considering reports will be made by users.
I've checked the work of the code. May be you always ran an Application with not empty DataSources ? In that case I also not received a message.
Please send an example of your Application to for analysis. May be some specific conditions do not allow the code to work properly. A highly interesting issue.
Okay, I finally see the message... after I shrink every window on the desktop...
I guess what I want to do is for the message to appear inside the preview control - so instead of displaying a blank page, it will display a message "No records". I am not quite sure what will be the easiest way to do this by code....
jing wrote:I guess what I want to do is for the message to appear inside the preview control - so instead of displaying a blank page, it will display a message "No records".
Instead of displaying a message I suggest you to use a blank page with StiText on it. Please use the following code in the EndRenderEvent:
Dim report As StiReport = TryCast(sender,StiReport)
Dim source As StiDataSource
For Each source In report.DataSources
If (source.Rows.Count = 0) Then
Do While (repor1.RenderedPages.Count > 0)
report.RenderedPages.RemoveAt(0)
Loop
Dim page As New StiPage
page.Report = report
Dim text As New StiText
text.Height = page.Height
text.Width = page.Width
text.Text = DirectCast("No records", StiExpression)
text.HorAlignment = StiTextHorAlignment.Center
text.VertAlignment = StiVertAlignment.Center
text.Font = New Font("Arial", 2000!, FontStyle.Bold)
text.TextBrush = New StiSolidBrush(Color.Red)
page.Components.Add(text)
report.RenderedPages.Add(page)
End If
Next