我怎样才能收到"滚动框"从一个DataGridView型涡旋事件? [英] How can I receive the "scroll box" type scroll events from a DataGridView?

查看:179
本文介绍了我怎样才能收到"滚动框"从一个DataGridView型涡旋事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataGridView,而我在听它的滚动的事件。这给了我一个ScrollEventArgs对象,其类型成员应该告诉我,已经发生的滚动事件的类型。在 MSDN文档页面它说我应该能够探测运动通过侦听与类型ThumbPosition,ThumbTrack,首先,最后和EndScroll事件滚动框。

然而,当我拖动滚动框,我只得到类型LargeDecrement和LargeIncrement的事件。

如何获得访问ThumbPosition,ThumbTrack,首先,最后和EndScroll事件?

解决方案

 使用的System.Reflection;
使用System.Windows.Forms的;

布尔addScrollListener(DataGridView中DGV)
{
    布尔RET = FALSE;

    类型t = dgv.GetType();
    的PropertyInfo PI = t.GetProperty(VerticalScrollBar,BindingFlags.Instance | BindingFlags.NonPublic可);
    滚动条S = NULL;

    如果(PI!= NULL)
        S = pi.GetValue(DGV,空)的滚动条;

    如果(S!= NULL)
    {
        s.Scroll + =新ScrollEventHandler(s_Scroll);
        RET = TRUE;
    }

    返回RET;
}

无效s_Scroll(对象发件人,ScrollEventArgs E)
{
    //投手去这里..
}
 

正如你所期望的,如果你想听听水平滚动的事件,你改变VerticalScrollBar到Horizo​​ntalScrollBar

I have a DataGridView, and I'm listening to its Scroll event. This gives me a ScrollEventArgs object whose Type member is supposed to tell me the type of scroll event that has occurred. On the MSDN documentation page it says I should be able to detect movement of the scroll box by listening for events with types ThumbPosition, ThumbTrack, First, Last and EndScroll.

However, when I drag the scroll box, I only get events of type LargeDecrement and LargeIncrement.

How do I get access to the ThumbPosition, ThumbTrack, First, Last and EndScroll events?

解决方案

using System.Reflection;
using System.Windows.Forms;

bool addScrollListener(DataGridView dgv)
{
    bool ret = false;

    Type t = dgv.GetType();
    PropertyInfo pi = t.GetProperty("VerticalScrollBar", BindingFlags.Instance | BindingFlags.NonPublic);
    ScrollBar s = null;

    if (pi != null)
        s = pi.GetValue(dgv, null) as ScrollBar;

    if (s != null)
    {
        s.Scroll += new ScrollEventHandler(s_Scroll);
        ret = true;
    }

    return ret;
}

void s_Scroll(object sender, ScrollEventArgs e)
{
    // Hander goes here..
}

As you'd expect, if you want to listen to horizontal scroll events, you change "VerticalScrollBar" to "HorizontalScrollBar"

这篇关于我怎样才能收到"滚动框"从一个DataGridView型涡旋事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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