DataGridView中鼠标倾斜水平滚动不起作用

3

I have a

 System.Windows.Forms.DataGridView 

带有水平滚动条。当我在这个DataGridView上进行鼠标倾斜时,内容并没有水平滚动。但是在

 ListView  

当我进行鼠标倾斜操作时,内容将水平滚动。那么我是否需要在DataGridView中设置其他属性以启用鼠标倾斜?还是这是DataGridView的一个错误?


DataGridView 接收到 WM_MOUSEHWHEEL(0x020e) 消息。但是 DataGridView 中的水平滚动并没有发生。 - NidhiSree
2个回答

0

试一下这个

 private void dataGridView1_Scroll(object sender, ScrollEventArgs e)
    {
      //get current selected rows
      DataGridViewSelectedRowCollection rc = dataGridView1.SelectedRows;

      if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
      {
        if (e.NewValue > e.OldValue && rc.Count > 0)
        {
          int nextrow = rc[0].Index + 1;
          dataGridView1.Rows[nextrow].Selected = true;
        }        
      }
    }

在 DGV 上倾斜鼠标滚轮既不会触发“Scroll”事件,也不会触发“MouseWheel”事件 :-( - TaW

0
要实现这个效果,您需要创建一个自定义的DataGridView。
    public sealed class MouseTiltableDataGridView : DataGridView
    {
        private const int WM_MOUSEHWHEEL = 0x020E;

        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            if (m.Msg == WM_MOUSEHWHEEL)
            {
                short w = (short)((m.WParam.ToInt32() >> 16) & 0xFFFF);
                if (HorizontalScrollingOffset + w >= 0)
                {
                    HorizontalScrollingOffset += w;
                }
            }
        }
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接