New to Telerik Reporting? Download free 30-day trial

Key and Mouse Events Not Raised When WinForms Report Viewer is Added to Form

Environment

Product Progress® Telerik® Reporting
Operating System Windows
.Net Framework Version 4+

Description

I have a blank RadForm. In the KeyDown event I am able to detect Ctrl-S. As soon as I place a WinForms ReportViewer on the Form, I am not longer able to detect Ctrl-S. I have tried both the Form KeyDown event and the ReportViewer KeyDown event.

How do I detect when the user presses the Ctrl-S key combination after the ReportViewer is added to the Form?

Solution

The KeyDown or other Key and Mouse events cannot be handled from the WinForms ReportViewer as they are raised by the Class WinViewer.

You may handle it from the RadForm or Form after setting the KeyPreview property of the Form to True.

The other workaround that you may use even without changing the above property, is to override the ProcessCmdKey method as shown below:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    if(keyData == (Keys.S | Keys.Control)) 
    { 
        //do my job
    }

    return base.ProcessCmdKey(ref msg, keyData);
}
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, keyData As Keys) As Boolean
    If (keyData = (Keys.S Or Keys.Control)) Then
        'do my job
    End If

    Return MyBase.ProcessCmdKey(msg, keyData)
End Function

Regarding the Mouse events you may use the approach suggested in the StackOverflow thread Capture mouse click anywhere on Form (without IMessageFilter).

See Also

In this article