我知道如何完成此操作的唯一方法是在运行时更改RDLC文件。基本上,您可以将RLDC文件加载到内存中(它只是一个XML文件),找到包含表宽度的XML节点-
然后修改内存中的设置。完成此操作后,您可以使用内存中加载的RDLC文件刷新reportViewer控件。
是的,我已经做到了,它确实有效。
下面的代码示例通过其XMLpath更改内存中RDLC文件的数据。
Private Sub ModifyRDLCInMemory() Dim xmlDoc As Xmldocument = New Xmldocument Dim asm As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly() 'create in memory, a XML file from a embedded resource Dim xmlStream As Stream = asm.GetManifestResourceStream(ReportViewer1.LocalReport.ReportEmbeddedResource) Try 'Load the RDLC file into a XML doc xmlDoc.Load(xmlStream) Catch e As Exception MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1) End Try 'Create an XmlNamespaceManager to resolve the default namespace Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(xmlDoc.Nametable) nsmgr.AddNamespace("nm", "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition") nsmgr.AddNamespace("rd", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner") 'Loop through each node in the XML file Dim node As XmlNode For Each node In xmlDoc.documentElement.SelectNodes(String.Format("//nm:{0}[@rd:LocID]", "Value"), nsmgr) 'XPath to LocID node.. You will want to change this to locate your Table Width node. You may need to read up on XMLPath Dim nodevalue As String = node.InnerText 'Gets current value of Node If (String.IsNullOrEmpty(nodevalue) Or Not nodevalue.StartsWith("=")) Then Try node.InnerText = YOURNEWVALUE Catch ex As Exception 'handle error End Try End If Next ReportViewer1.LocalReport.ReportPath = String.Empty ReportViewer1.LocalReport.ReportEmbeddedResource = Nothing 'Load the updated RDLC document into LocalReport object. Dim rdlcOutputStream As StringReader = New StringReader(xmlDoc.documentElement.OuterXml) Using rdlcOutputStream ReportViewer1.LocalReport.LoadReportDefinition(rdlcOutputStream) End Using End Sub


