cancel
Showing results for 
Search instead for 
Did you mean: 

Null Reference when using the mouse wheel to scroll to a new page

Former Member
0 Kudos

I'm using Crystal Reports with VS.Net 2003. Crystal reports lacks mouse wheel support when viewing reports in a crystal report viewer object. I added code to allow using the mouse wheel to scroll. I thought it would be nice to automatically scroll up to the previous page if the upper scroll limit is reached and scroll down to the next page if the lower scroll limit is reached. All that works fine, however, if a user holds down/presses the mouse wheel button as they scroll to a new page I receive the following exception:

System.NullReferenceException: Object reference not set to an instance of an object.

at CrystalDecisions.Windows.Forms.PageControl.OnMouseMove(MouseEventArgs e)

at System.Windows.Forms.Control.WmMouseMove(Message& m)

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.ScrollableControl.WndProc(Message& m)

at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)

at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)

at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

I'm guessing it has to do with the fact that the mouse button press event is on one instance of the page control and when I call ShowNextPage() or ShowPreviousPage() that object becomes invalid. That's just a guess. I can't figure out how/where to trap this error, or find a solution to the problem. Any help would be greatly appreciated.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

This error is generally obtained due to error in code and I agree with you that the object is unavailable in other two pages.

If you are using a web based application then you can use the sessions to pass the object which I believe might be a reportdocument object and then apply your logic in the next page. In case of a windows based application a class file or global variable would do the same. However, you need to be sure that you clean up the session or variable at some point of time to avoid any unnecessary trouble.

As this is about the objects and its value in it I believe by this way we can easily verify if the objects are getting the proper value or not rather than putting breakpoints and stepping through or using try-catch block.

Just wondering why are we not using the navigation keys in viewer?

Does it help?

Regards,

AG.

Former Member
0 Kudos

Hello,

I'm working with a windows based application, and I tried the global variable approach with no success. I've since determined I'm not able to trap the error because it's generated outside of the MouseWheel event, and due to some code a guy wrote years ago, I can't trap the error.

I wasn't trying to replace the navigation keys that the viewer provides, but rather provide additional functionality. I like being able to use the mouse wheel to scroll through numerous pages (like viewing pdfs in adobe reader). I'm just going to scrap the page transition part and only allow scrolling on a single page.

Thanks for the help,

Seth

Answers (0)