Search code examples
reportcomponentoneprint-preview

Jump to Page in C1PrintDocument


I have a form in my application that is used for previewing a report. It has a C1Ribbon at the top which contains navigation buttons, and a C1PrintPreview displaying in a PreviewPane. I want the navigation buttons in the ribbon (first, previous, next, last), as well as a text box in which to enter a specific page number, to navigate through the preview of the report accordingly. So far, all the documentation and samples I've found have dealt only with adding hyperlinks directly to the report itself...so I'm having a hard time adapting it to my use. Below is what I have so far...I don't get any build or run-time errors, it just doesn't do anything.

Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
    Dim nextPage As C1LinkTargetPage = New C1LinkTargetPage(PageJumpTypeEnum.Next)
End Sub

Private Sub btnLast_Click(sender As Object, e As EventArgs) Handles btnLast.Click
    Dim lastPage As C1LinkTargetPage = New C1LinkTargetPage(PageJumpTypeEnum.Last)
End Sub

Private Sub btnPrevious_Click(sender As Object, e As EventArgs) Handles btnPrevious.Click
    Dim prevPage As C1LinkTargetPage = New C1LinkTargetPage(PageJumpTypeEnum.Previous)
End Sub

Private Sub btnFirst_Click(sender As Object, e As EventArgs) Handles btnFirst.Click
    Dim firstPage As C1LinkTargetPage = New C1LinkTargetPage(PageJumpTypeEnum.First)
End Sub

Private Sub Navigation_KeyDown(sender As Object, e As KeyEventArgs) Handles txtPageNum.KeyDown
    If e.Modifiers = Keys.Enter Then
        Dim setPage As C1LinkTargetPage = New C1LinkTargetPage(PageJumpTypeEnum.Absolute)
        'setPage. = CInt(txtPageNum.Text)
        If setPage.PageNo = 0 Then
            'what to do if number entered is not a page in document
        End If
    End If
End Sub

I realize it's likely just because even though I make a C1LinkTargetPage, I don't tell the app what to do with it after that. But I'm not sure how to go about doing that - it's not like there's a "jumptopage" method for the C1PrintPreview (wish it were that easy). Buttons in the ribbon don't have a hyperlink property, so I can't set that when the form loads as in all the samples I found. Not sure where to go from here... Also I don't even know how I'm supposed to be able to use the Absolute PageJumpTypeEnum...PageNo is read only.

Thank you!

UPDATE 2/25:

I learned that I should be dealing with properties of the Preview Pane...not the C1PrintDocument. With the code below, the navigation buttons and specifying a page number work. My only problem now then is displaying the current page in that page number box. With what I have, PreviewPane.CurrentHistoryEntry just goes to 1 (even if I was on a page other than 1 before-hand).

Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
    PreviewPane.DoGoNextPage()
End Sub

Private Sub btnLast_Click(sender As Object, e As EventArgs) Handles btnLast.Click
    Dim lastPage As DocumentLocation = New DocumentLocation(report.Pages(report.Pages.Count - 1))
    PreviewPane.GotoDocumentLocation(lastPage)
End Sub

Private Sub btnPrevious_Click(sender As Object, e As EventArgs) Handles btnPrevious.Click
    PreviewPane.DoGoPreviousPage()
End Sub

Private Sub btnFirst_Click(sender As Object, e As EventArgs) Handles btnFirst.Click
    Dim firstPage As DocumentLocation = New DocumentLocation(report.Pages(0))
    PreviewPane.GotoDocumentLocation(firstPage)
End Sub

Private Sub Navigation_KeyDown(sender As Object, e As KeyEventArgs) Handles txtPageNum.KeyDown
    If e.KeyValue = Keys.Enter Then
        Dim pageNum As Integer = CInt(txtPageNum.Text)
        If (pageNum > 0) And (pageNum <= report.Pages.Count) Then
            Dim setPage As DocumentLocation = New DocumentLocation(report.Pages(pageNum - 1))
            PreviewPane.GotoDocumentLocation(setPage)
        Else
            txtPageNum.Text = PreviewPane.CurrentHistoryEntry.ToString
        End If
    End If
End Sub

Solution

  • They key was "PreviewPane.StartPageIdx"

    txtPageNum.Text = (PreviewPane.StartPageIdx + 1).ToString