Igor
Igor

Reputation: 1592

DataGridView mouse wheel scrolling stopped working

I have a DataGridView in my app and I can't scroll it using the mousewheel. It used to work fine before. I'm not sure what I have done to cause this because I only noticed it recently after I had made multiple changes to the code.

I'm not posting any code because there are more than 2k lines and I'm not sure where the error could possibly be.

Any ideas what might have caused this? If you need any code I can edit the question afterwards.

Upvotes: 5

Views: 4228

Answers (1)

Adam
Adam

Reputation: 2802

Almost certainly the problem occurs because the DataGridView has lost focus. This can be because another control on your form demands focus or your form is set by default to give a different control focus.

You can force the DataGridView to have focus. If you want to emulate the standard Microsoft Windows behavior of enabling mouse wheel scroll when the mouse is hovering over the control then just use the code below.

private void SettingsGrid_MouseEnter(object sender, EventArgs e)
{
     dataGridView1.Focus();
}

If you want to scroll the grid regardless of what control has focus then the code will be similar to above with a little beak of tweaking.

Upvotes: 7

Related Questions