如何在C#WINForm datagridview中发生鼠标滚轮事件时滚动条记事滚动

时间:2012-10-29 06:12:01

标签: c# winforms events datagridview mouseevent

  

可能重复:
  C# - how do I prevent mousewheel-scrolling in my combobox?
  Disable mouse scroll wheel in combobox VB.NET

所有     我有一个问题,当我进行鼠标滚动时,我想让VerticalScrollBar不在Datagridview中滚动。

我得到了一些像这样的代码:

  private void dgwFlowerPics_MouseWheel(object sender, MouseEventArgs e)
    {
        int iRowIndex = iSelectedIndex;
        if (e.Delta > 0) 
        {
            SendKeys.Send("{UP}");  


        }
        else 
        {
            SendKeys.Send("{DOWN}"); 
        }
    }

但是当滚轮鼠标时,滚动条仍会滚动。我如何解决它?

1 个答案:

答案 0 :(得分:1)

我认为这类似于C# - how do I prevent mousewheel-scrolling in my combobox?

在您的活动代码中,您可以

    void dataGridView1_MouseWheel(object sender, MouseEventArgs e)
    {
        ((HandledMouseEventArgs)e).Handled = true;
    }
绑定事件后

当然:

dataGridView1.MouseWheel += new MouseEventHandler(dataGridView1_MouseWheel);