我如何听在ListView滚动? [英] How do I listen for scrolling in a ListView?

查看:146
本文介绍了我如何听在ListView滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ListView控件似乎并不支持Scroll事件。我需要调用每当列表滚动功能;我将如何去有关?

The ListView doesn't seem to support the Scroll event. I need to call a function whenever the list is scrolled; how would I go about that?

推荐答案

为什么你需要调用一个函数时,列表滚动?

Why do you need to call a function when the list is scrolled?

如果您要更改的项目,因为它的滚动我会建议列表视图设置为虚拟的。

If you are changing the items as it's scrolled i would recommend setting the listview to virtual.

或者你可以重写ListView和做到这一点:

Or you could override the listview and do this:

public class TestListView : System.Windows.Forms.ListView
{
    private const int WM_HSCROLL = 0x114;
    private const int WM_VSCROLL = 0x115;
    public event EventHandler Scroll;

    protected void OnScroll()
    {

        if (this.Scroll != null)
            this.Scroll(this, EventArgs.Empty);

    }

    protected override void WndProc(ref System.Windows.Forms.Message m)
    {
        base.WndProc(ref m);
        if (m.Msg == WM_HSCROLL || m.Msg == WM_VSCROLL)
            this.OnScroll();
    }
}

这篇关于我如何听在ListView滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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