SSRS - Сохранить таблицу той же шириной при сокрытии столбцов динамично?

Dictionary<T1, Tuple<T2, T3>>

Редактирование: Извините - я забыл, что Вы не получаете Кортежи, пока.NET 4.0 не выходит. D'oh!

9
задан JoeB 17 September 2009 в 17:57
поделиться

1 ответ

Единственный способ, которым я знаю, как это сделать, - это изменить файл RDLC во время выполнения. По сути, вы можете загрузить файл RLDC в память (это просто файл XML), найти узел XML, который содержит ширину вашей таблицы, а затем изменить настройку в памяти. Как только вы это сделаете, вы можете обновить элемент управления reportViewer, используя файл RDLC, который загружен в память.

И да, я уже сделал это, и это работает.

--- РЕДАКТИРОВАТЬ --- Следующий пример кода предназначен для изменения данных файла RDLC в памяти с помощью его XMLpath.

  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
6
ответ дан 4 December 2019 в 23:40
поделиться
Другие вопросы по тегам:

Похожие вопросы: