Home All Groups Group Topic Archive Search About

Changing text in Report viewer

Author
9 Jun 2006 12:19 AM
steve
Hi All

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

Author
9 Jun 2006 12:16 PM
Steven Cheng[MSFT]
Hello 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.)
Author
9 Jun 2006 9:33 PM
steve
Steven

Thanks very much for both your posts

Exactly what I was looking for


Regards
Steve

Show quoteHide quote
"Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message
news:GLt0k67iGHA.5720@TK2MSFTNGXA01.phx.gbl...
> Hello 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.)
>
>
>
Author
10 Jun 2006 5:07 AM
Steven Cheng[MSFT]
You're welcome Steve,

Glad to be of assistance. BTW, I also think Oenone's suggestion a good idea
:).

Have a good day!

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.)
Author
10 Jun 2006 6:08 AM
steve
Hi All

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

Show quoteHide quote
"Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message
news:cqjRGvEjGHA.4828@TK2MSFTNGXA01.phx.gbl...
> You're welcome Steve,
>
> Glad to be of assistance. BTW, I also think Oenone's suggestion a good
> idea
> :).
>
> Have a good day!
>
> 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.)
>
Author
12 Jun 2006 4:00 AM
Steven Cheng[MSFT]
Hi Steve,

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.

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.)
Author
9 Jun 2006 8:09 PM
Oenone
steve wrote:
> How do I access the textbox in "GymMaster.Memberships.rdlc" (below) to
> change the text

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
Author
9 Jun 2006 9:34 PM
steve
Oenone

Thanks for the post

An interesting concept which I hadn't thought of

I will experiment


Regards
Steve

Show quoteHide quote
"Oenone" <oen***@nowhere.com> wrote in message
news:3Akig.707$s4.311@newsfe3-win.ntli.net...
> steve wrote:
>> How do I access the textbox in "GymMaster.Memberships.rdlc" (below) to
>> change the text
>
> 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
>