Crystalreportviewer - setting focus

CygNuS

Well-known member
Joined
Aug 21, 2006
Messages
89
Location
Belgium
Programming Experience
Beginner
I have a form with a crystalreportviewer control on it.
I would like that, when it loads, the focus is set on the page, so that PageUp, PageDn will work immediately instead of having to click the navigate buttons (or instead of clicking the page first (so it has the focus) and then pressing PgUp, PgDn)

Come to think of it, is it even possible to set focus on anything (button, page,...) in the crystalreportviewer control?
 
I hope I get it right, I assume you have a crytal report view being embedded in your form. Now you can set the form's KeyPrevious to True, and putting the following code in the form's KeyUp event:


VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] frmReport_KeyUp([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Windows.Forms.KeyEventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].KeyUp
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] e.KeyCode = Keys.PageDown [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].crpViewer.ShowNextPage()
[/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] e.KeyCode = Keys.PageUp [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].crpViewer.ShowPreviousPage()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]
 
That is a nice workaround and it does the job great, except i had to put it in the ProcessCmdKey event and not in the form's keyup/keydown event (for some reason the keyup/down event never got triggered, even with focus on the form)

Thx a lot!

VB.NET:
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
        If keyData = Keys.PageDown Then
               Me.myViewer.ShowNextPage()
               Return True
        ElseIf keyData = Keys.PageUp Then
               Me.Viewer.ShowPreviousPage()
               Return True
        ElseIf keyData = Keys.Right Then
               Me.Viewer.ShowNextPage()
               Return True
        ElseIf keyData = Keys.Left Then
               Me.Viewer.ShowPreviousPage()
               Return True
        Else
              Return MyBase.ProcessCmdKey(msg, keyData) 'lets the form process further info 
        End If
End Function
 
Of course, i guess i didn't pay enough attention. Let's just blame it on that monday morning feeling :D
Thx
 
Back
Top