I need to change text in a Report Viewer document at runtime
It is just the heading I want to change to match what the user has chosen as
the Report to view
How do I access the textbox in "GymMaster.Memberships.rdlc" (below) to
change the text
sql = "select * from members order by surname"
dt = getdata(sql)
If Me.ReportViewer1.LocalReport.DataSources.Count > 0 Then
Me.ReportViewer1.LocalReport.DataSources.RemoveAt(0)
End If
Me.ReportViewer1.LocalReport.ReportEmbeddedResource =
"GymMaster.Memberships.rdlc"
Me.ReportViewer1.LocalReport.DataSources.Add(New
Microsoft.Reporting.WinForms.ReportDataSource("Gym_masterDataSet_Members",
dt))
Me.ReportViewer1.RefreshReport()
Regards
Steve
Thanks for your posting.
I've also seen your previous thread about the "VB 2005 reportviewer help"
and posted my suggestion on how to dynamically change the report's
datasource and refresh it. And as for your question in this thread, my
understanding is that you want to do some customization on the
reportViewer's LocalReport definiation content(rdlc) in program code at
runtime, correct?
As for the ReportViewer.LocalReport, it has provided several means to
specify the Local Report's definition template. If we use the
"LocalReport.ReportPath" or "LocalReport.ReportEmbeddedResource" property
to supply the rdlc template, we will be unable to intercept and modify the
report definition because the ReportViewer will load and parse the rdlc
content internally(from filestream or assembly resource stream). However,
the LocalReport also provide another method named "LoadReportDefinition",
this provide us the chance to manually load and supply the rdlc template(so
that we can customize it before assign to reportviewer)
#LocalReport.LoadReportDefinition Method (TextReader)
http://msdn2.microsoft.com/en-us/library/ms251812.aspx
for example, in the below code, I manually load the rdlc stream from
assembly resource and assign it to the reportviewer. And before assigning
the stream to reportviewer's localreport, I load it into a XmlDocument and
do some customization(use Xpath to locate the categoryName" textbox node
and modify it to a new value):
==========================
Private Sub btnClientTest2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnClientTest2.Click
Me.ReportViewer1.Reset()
Me.ReportViewer1.ProcessingMode =
Microsoft.Reporting.WinForms.ProcessingMode.Local
Dim newds As New
Microsoft.Reporting.WinForms.ReportDataSource("NorthwindDataSet_Categories")
newds.Value = Me.CategoriesBindingSource
Me.ReportViewer1.LocalReport.DataSources.Add(newds)
' load the customized report template
Me.ReportViewer1.LocalReport.LoadReportDefinition(GetCustomizedReportDefinit
ion("ClientReportApp.Report1.rdlc"))
Me.ReportViewer1.RefreshReport()
End Sub
Private Function GetCustomizedReportDefinition(ByVal rdlc As String) As
IO.TextReader
Dim reader As IO.TextReader
Dim doc As New Xml.XmlDocument
Dim stream As IO.Stream
stream = GetType(Form1).Assembly.GetManifestResourceStream(rdlc)
doc.Load(stream)
Dim node As Xml.XmlNode
Dim nsmgr As New Xml.XmlNamespaceManager(doc.NameTable)
nsmgr.AddNamespace("dns",
"http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition")
node =
doc.SelectSingleNode("//dns:Table[@Name='table1']//dns:Header//dns:Textbox[@
Name='textbox2']/dns:Value", nsmgr)
node.InnerText = "new" & node.InnerText
reader = New IO.StringReader(doc.OuterXml)
Return reader
End Function
=============================
Hope this helps.
Regards,
Steven Cheng
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Another way you could do this is by setting the textbox to display its value
from a datasource rather than hard-coding the value into the report
definition. Then you can just give a DataTable to the report viewer and
it'll display the appropriate value from within.
--
(O)enone
Thanks very much for both your posts
Exactly what I was looking for
Regards
Steve
"Steven Cheng[MSFT]" <stc...@online.microsoft.com> wrote in message
news:GLt0k67i...@TK2MSFTNGXA01.phx.gbl...
Thanks for the post
An interesting concept which I hadn't thought of
I will experiment
Regards
Steve
"Oenone" <oen...@nowhere.com> wrote in message
news:3Akig.707$s4....@newsfe3-win.ntli.net...
Glad to be of assistance. BTW, I also think Oenone's suggestion a good idea
:).
Have a good day!
I have created rdlc files and when I load them into Report Viewer at run
time they appear OK
If I click on 'Print layout' button on Report Viewer the view again appears
acceptable
If I click on 'Page setup' button the margins left & right are not what I
set on the rdlc file at design time (1.5cm) they are 5.9mm
If I click OK on the 'Page Setup' form the Report margins change to the
margins from 'Page setup'
If I open ''Page setup' again the margin settings are now less than
previously set and clicking OK results in the report margins changing again
What am I missing??
Regards
Steve
"Steven Cheng[MSFT]" <stc...@online.microsoft.com> wrote in message
news:cqjRGvEj...@TK2MSFTNGXA01.phx.gbl...
I've seen your new thread on this issue and posted my response in that
thread. As I also mentioned there, if you feel it convenient that we
continue discussing in that thread, please feel free to followup there. And
I'll close this thread first.
Thanks for your understanding.