Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

DataBound WPF FlowDocument output is mixed up

$
0
0

Hello;

I’m trying to create a FlowDocument so I can allow the user to Print it or to Save it. The Data Content for the document comes from a Query to a WebService. Some Tables in the DataSet have only one row and some have several rows depending on the selections the user made.

I have no problem creating my FlowDocument as long as there is only one row per table in the DataSet. However, if there are multiple rows, things get messed up.

You’ll see in my code below that where I iterate through the rows of the Table in my DataSet  It creates a Paragraph for the Period, a table and a Paragraph for the comments. At the end of each section, I add the Paragraph Block to the Section.

All of the data is successfully displayed to the DocViewer except that it’s mangled.

If there are more than one row, then periods appear side by side, the tables  appear wherever and all the comments appear at the bottom.

If I had two rows in my DataSet, it should look like this:

Objective & Achievements

2012 Q3

<The static Data table for the period>

<The comment text for the period>

2012 Q4

<The static Data table for the period>

<The comment text for the period>

Instead I get something that looks like this

Objective & Achievements

<The static Data table for the period>

2012 Q32012 Q4

<The static Data table for the period>

<The comment text for the first period>

<The comment text for the second period>

Any idea what I’m doing wrong? I’ve stepped through the code and it’s hitting every Inlines.Add and Blocks.Add that it should. I’ve added a bunch of Debug.Prints to see the Block Count after each Block add and it increments fine over the first iteration, but it doesn’t increment after the last Blocks.Add of each iteration.

I appreciate any insights anyone could provide.

Thanks in advance for your time and effort.

Function BuildObjectivesAndAchievements() As Section
        Dim ObjectivesAndAchievements As New Section
        Dim ObjectivesAndAchievementsTitle As New Paragraph
        Dim ObjectivesAndAchievementsPeriod As New Paragraph
        Dim ObjectivesAndAchievementsComments As New Paragraph
        Dim currentRow As New TableRow

        ' Set the Font Size & Color for Objectives & Achievements
        ObjectivesAndAchievements.FontFamily = New FontFamily("Tahoma")
        ObjectivesAndAchievements.FontSize = 12.0
        ObjectivesAndAchievements.FontWeight = FontWeights.Normal
        ObjectivesAndAchievements.Foreground = Brushes.Black
        ObjectivesAndAchievements.TextAlignment = TextAlignment.Left

        ' Print the Talk Area
        ObjectivesAndAchievementsTitle.FontFamily = New FontFamily("Calibri")<<< Removed Text Formatting Code >>>
        ObjectivesAndAchievementsTitle.Inlines.Add(New Run("Objectives and Achievements"))
        ObjectivesAndAchievements.Blocks.Add(ObjectivesAndAchievementsTitle)
        ' Check to see if there is any data for the period
        If dsPrtData.Tables(2).Rows.Count < 1 Then
            ObjectivesAndAchievements.Blocks.Add(NoData)
            Return ObjectivesAndAchievements
        End If

        ' Iterate through all the rows in the O&A Table
        For r As Int16 = 0 To dsPrtData.Tables(2).Rows.Count - 1
            ' Print the Period<<< Removed Text Formatting Code >>>
            ObjectivesAndAchievementsPeriod.Inlines.Add(New Run("For Period: " & dsPrtData.Tables(2).Rows(r).Item("Period")))
            ObjectivesAndAchievements.Blocks.Add(ObjectivesAndAchievementsPeriod)
            ' Create a table to define the Static Data at time of QCI
            Dim tblObjectivesAndAchievements = New Table()<<< Removed Text Formatting Code >>>

            For x As Int16 = 0 To 3
                tblObjectivesAndAchievements.Columns.Add(New TableColumn)
            Next

            ' Setup the Column Widths
            tblObjectivesAndAchievements.Columns(0).Width = New GridLength(150)
            tblObjectivesAndAchievements.Columns(1).Width = New GridLength(50)
            tblObjectivesAndAchievements.Columns(2).Width = New GridLength(100)
            tblObjectivesAndAchievements.Columns(3).Width = New GridLength(250)

            ' Add the 2 table rows.
            tblObjectivesAndAchievements.RowGroups.Add(New TableRowGroup())
            tblObjectivesAndAchievements.RowGroups(0).Rows.Add(New TableRow())
            tblObjectivesAndAchievements.RowGroups(0).Rows.Add(New TableRow())

            currentRow = tblObjectivesAndAchievements.RowGroups(0).Rows(0)
            <<< Removed Text Formatting Code >>>

            ' Setup the Column Header row
            currentRow.Cells.Add(New TableCell(New Paragraph(New Run("Title at time of Check-In"))))
            currentRow.Cells.Add(New TableCell(New Paragraph(New Run("Level"))))
            currentRow.Cells.Add(New TableCell(New Paragraph(New Run("Manager"))))
            currentRow.Cells.Add(New TableCell(New Paragraph(New Run("Organization"))))
            currentRow = tblObjectivesAndAchievements.RowGroups(0).Rows(1)<<< Removed Text Formatting Code >>>

            ' Setup the data row
            currentRow.Cells.Add(New TableCell(New Paragraph(New Run(dsPrtData.Tables(2).Rows(r).Item("EmpTitle")))))
            currentRow.Cells.Add(New TableCell(New Paragraph(New Run(dsPrtData.Tables(2).Rows(r).Item("EmpLevel")))))
            currentRow.Cells.Add(New TableCell(New Paragraph(New Run(dsPrtData.Tables(2).Rows(r).Item("Manager")))))
            currentRow.Cells.Add(New TableCell(New Paragraph(New Run(dsPrtData.Tables(2).Rows(r).Item("EmpOrganization")))))
            ObjectivesAndAchievements.Blocks.Add(tblObjectivesAndAchievements)

            ' setup the Comments Data and add it to the document
            <<< Removed Text Formatting Code >>>
            ObjectivesAndAchievementsComments.Inlines.Add(New Run(dsPrtData.Tables(2).Rows(r).Item("EmpComment")))
            ObjectivesAndAchievementsComments.Inlines.Add(New LineBreak)
            ObjectivesAndAchievementsComments.Inlines.Add(New LineBreak)
            ObjectivesAndAchievementsComments.Inlines.Add(New Run(dsPrtData.Tables(2).Rows(r).Item("MgrComment")))
            ObjectivesAndAchievementsComments.Inlines.Add(New LineBreak)
            ObjectivesAndAchievements.Blocks.Add(ObjectivesAndAchievementsComments)
        Next r

        ' Done building the Objectives & Achievements section - Return the Section to the caller
        Return ObjectivesAndAchievements

    End Function


Thanks Ron...


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>