DataGridView的滚动使用鼠标 [英] Scrolling DataGridView with Mouse

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

问题描述

所以我们都很熟悉点击的功能,并按住鼠标左键,然后将鼠标移动到格栅的边缘,列/行滚动和选择成长。

So we are all familiar with the functionality of click and holding down the mouse button, then moving the mouse to the edge of a grid, and the columns/rows scroll and the selection grows.

我有一个基于DataGridView的控制,我不得不把多选关闭和处理选择过程中自己由于性能问题,现在点击+保持滚动功能也被禁用。

I have a DataGridView-based control that I had to turn MultiSelect off and handle the selection process myself due to performance issues, and now the click+hold scrolling feature is disabled as well.

关于如何去在这个功能写回有什么建议?

Any suggestions about how to go about writing back in this functionality?

我想用一些简单的像MouseLeave事件中,但我不知道如何确定它留下了位置,并实施动态的滚动速度。

I was thinking of using something simple like the MouseLeave event, but I'm not sure how to determine which position it left, as well as implementing a dynamic scroll speed.

推荐答案

只需添加这段代码到你的 Form1_Load的

Just add this code to your Form1_Load

DataGridView1.MouseWheel += new MouseEventHandler(DataGridView1_MouseWheel);

和这个人是MouseWheel事件

And this one is for the MouseWheel event

void DataGridView1_MouseWheel(object sender, MouseEventArgs e)
{
    int currentIndex = this.DataGridView1.FirstDisplayedScrollingRowIndex;
    int scrollLines = SystemInformation.MouseWheelScrollLines;

    if (e.Delta > 0) 
    {
        this.DataGridView1.FirstDisplayedScrollingRowIndex 
            = Math.Max(0, currentIndex - scrollLines);
    }
    else if (e.Delta < 0)
    {
        this.DataGridView1.FirstDisplayedScrollingRowIndex 
            = currentIndex + scrollLines;
    }
}

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

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