Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 63035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:34:10+00:00 2026-05-10T18:34:10+00:00

We’d like to override DataGridView’s default behavior when using a mouse wheel with this

  • 0

We’d like to override DataGridView’s default behavior when using a mouse wheel with this control. By default, the DataGridView scrolls a number of rows equal the SystemInformation.MouseWheelScrollLines setting. What we’d like to do is scroll just one item at a time.

(We display images in the DataGridView, which are somewhat large. Because of this scroll three rows (a typical system setting) is too much, often causing the user to scroll to items they can’t even see.)

I’ve tried a couple things already and haven’t had much success so far. Here are some issues I’ve run into:

  1. You can subscribe to MouseWheel events but there’s no way to mark the event as handled and do my own thing.

  2. You can override OnMouseWheel but this never appears to be called.

  3. You might be able to correct this in the base scrolling code but it sounds like a messy job since other types of scrolling (e.g. using the keyboard) come through the same pipeline.

Anyone have a good suggestion?

Here’s the final code, using the wonderful answer given:

    /// <summary>     /// Handle the mouse wheel manually due to the fact that we display     /// images, which don't work well when you scroll by more than one     /// item at a time.     /// </summary>     ///      /// <param name='sender'>     /// sender     /// </param>     /// <param name='e'>     /// the mouse event     /// </param>     private void mImageDataGrid_MouseWheel(object sender, MouseEventArgs e)     {         // Hack alert!  Through reflection, we know that the passed         // in event argument is actually a handled mouse event argument,         // allowing us to handle this event ourselves.         // See http://tinyurl.com/54o7lc for more info.         HandledMouseEventArgs handledE = (HandledMouseEventArgs) e;         handledE.Handled = true;          // Do the scrolling manually.  Move just one row at a time.         int rowIndex = mImageDataGrid.FirstDisplayedScrollingRowIndex;         mImageDataGrid.FirstDisplayedScrollingRowIndex =             e.Delta < 0 ?                 Math.Min(rowIndex + 1, mImageDataGrid.RowCount - 1):                 Math.Max(rowIndex - 1, 0);     } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:34:11+00:00Added an answer on May 10, 2026 at 6:34 pm

    I just did a little scrounging and testing of my own. I used Reflector to investigate and discovered a couple things. The MouseWheel event provides a MouseEventArgs parameter, but the OnMouseWheel() override in DataGridView casts it to HandledMouseEventArgs. This also works when handling the MouseWheel event. OnMouseWheel() does indeed get called, and it is in DataGridView‘s override that it uses SystemInformation.MouseWheelScrollLines.

    So:

    1. You could indeed handle the MouseWheel event, casting MouseEventArgs to HandledMouseEventArgs and set Handled = true, then do what you want.

    2. Subclass DataGridView, override OnMouseWheel() yourself, and try to recreate all the code I read here in Reflector except for replacing SystemInformation.MouseWheelScrollLines with 1.

    The latter would be a huge pain because it uses a number of private variables (including references to the ScrollBars) and you’d have replace some with your own and get/set others using Reflection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I found a file in the Office 2003 toolkit, Office… May 11, 2026 at 11:02 am
  • added an answer Going by your edit, have you tried moving the App_Code… May 11, 2026 at 11:02 am
  • added an answer Vista added support for canonical names so you don't have… May 11, 2026 at 11:02 am

Related Questions

We are developing a little application that given a directory with PDF files creates
We have been using CruiseControl for quite a while with NUnit and NAnt. For
We have a requirement in project to store all the revisions(Change History) for the
We have a remoting singleton server running in a separate windows service (let's call
We have an SVN repository running on a Windows server, and I want to
We currently maintain a suit of MFC applications that are fairly well designed, however
We have a Windows Server Web Edition 2003 Web Farm. What can we use
We have a situation where users are allowed to upload content, and then separately
We get a large amount of data from our clients in pdf files in
We have a SharePoint list setup with history enabled so the Comments field keeps

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.