DataGridView鼠标滚轮滚动工作 [英] DataGridView mouse wheel scrolling stoped working
问题描述
我不会发布任何代码,因为有超过2k行,我不知道错误可能在哪里。
有什么想法可能造成这个?如果您需要任何代码,我可以随时编辑该问题。
几乎肯定会出现此问题,因为DataGridView已失去焦点。这可能是因为您的表单上的另一个控件需要重点或默认设置您的表单以给出不同的控制焦点。
您可以强制DataGridView具有焦点。如果要模拟当鼠标悬停在控件上时启用鼠标滚轮滚动的标准Microsoft Windows行为,那么只需使用下面的代码。
private void SettingsGrid_MouseEnter(object sender,EventArgs e)
{
dataGridView1.Focus();
}
如果你想滚动网格,不管什么控件有焦点,代码将类似于上面的一点点调整。
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.
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.
这篇关于DataGridView鼠标滚轮滚动工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!