Page 1 of 1
StiEndRenderEvent
Posted: Mon Feb 19, 2007 6:13 pm
by jing
Hi,
Is there an easier way to rewrite the StiEndRenderEvent on a report?
I have been doing
Code: Select all
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....
Thanks a lot
StiEndRenderEvent
Posted: Tue Feb 20, 2007 4:10 am
by Edward
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:
Code: Select all
Dim report As New StiReport
report.Compile
AddHandler report.CompiledReport.EndRender, New EventHandler(AddressOf Me.report_EndRender)
report.Show
Thank you.
StiEndRenderEvent
Posted: Tue Feb 20, 2007 3:05 pm
by jing
Hi,
Thanks for the code. I am now having problem using MessageBox.Show in the EndRender event in conjunction with the preview control.....
Code: Select all
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....
How can I get around this?
thank you
StiEndRenderEvent
Posted: Wed Feb 21, 2007 3:21 am
by Edward
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....
The following line of the code
Code: Select all
report.PreviewControl = StiPreviewControl1
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.
Thank you.
StiEndRenderEvent
Posted: Wed Feb 21, 2007 2:29 pm
by jing
Hi,
Thanks for your reply.
The following lines of code are placed in the Form_Load event (The form that has the StiPreviewControl1 on)
Code: Select all
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.
StiEndRenderEvent
Posted: Thu Feb 22, 2007 2:24 am
by Edward
Your code is absolutely correct.
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.
Thank you.
StiEndRenderEvent
Posted: Thu Feb 22, 2007 2:46 pm
by jing
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....
Any help on this?
thanks
StiEndRenderEvent
Posted: Fri Feb 23, 2007 1:32 am
by Edward
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:
Code: Select all
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
Thank you.