DataGridView鼠标滚轮滚动停止工作 [英] DataGridView mouse wheel scrolling stopped working

查看:163
本文介绍了DataGridView鼠标滚轮滚动停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一个DataGridView,但无法使用鼠标滚轮滚动它。以前工作正常。我不确定该怎么做,因为我只是在对代码进行了多次更改之后才注意到这一点。

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.

我没有发布任何代码,因为行数超过2k,我不确定错误可能在哪里。

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.

推荐答案

几乎可以肯定,由于DataGridView失去了焦点,因此出现了问题。这可能是因为窗体上的另一个控件需要焦点,或者默认情况下窗体被设置为赋予其他控件焦点。

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.

您可以强制DataGridView拥有焦点。如果要模拟标准的Microsoft Windows行为,即当鼠标悬停在控件上时启用鼠标滚轮滚动,则只需使用下面的代码。

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.

这篇关于DataGridView鼠标滚轮滚动停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆