检测ListView滚动条何时到达WinForms的底部

我如何知道WinForms ListView滚动条到达底部的时间? 当发生这种情况时,我希望listview中填充更多数据(在我的案例中,这在理论上是无穷无尽的)。

OnScroll事件从顶部给我滚动值,但我无法知道用户是否可以进一步滚动。

我使用伟大的ObjectListView代码项目中的一些代码找到了答案: http : //www.codeproject.com/KB/list/ObjectListView.aspx

调用GetScrollInfo:

private const int SIF_RANGE = 0x0001; private const int SIF_PAGE = 0x0002; private const int SIF_POS = 0x0004; private const int SIF_DISABLENOSCROLL = 0x0008; private const int SIF_TRACKPOS = 0x0010; private const int SIF_ALL = (SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS); private const int SB_HORZ = 0; private const int SB_VERT = 1; [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] public static extern bool GetScrollInfo(IntPtr hWnd, int fnBar, SCROLLINFO scrollInfo); public static SCROLLINFO GetFullScrollInfo(ListView lv, bool horizontalBar) { int fnBar = (horizontalBar ? SB_HORZ : SB_VERT); SCROLLINFO scrollInfo = new SCROLLINFO(); scrollInfo.fMask = SIF_ALL; if (GetScrollInfo(lv.Handle, fnBar, scrollInfo)) return scrollInfo; else return null; } 

使用此数据结构:

  [StructLayout(LayoutKind.Sequential)] public class SCROLLINFO { public int cbSize = Marshal.SizeOf(typeof(SCROLLINFO)); public int fMask; public int nMin; public int nMax; public int nPage; public int nPos; public int nTrackPos; } 

nMax给出包括滚动句柄本身的总最大滚动值,因此实际有用的最大值是nMax -nPage,其中nPage是滚动句柄的大小。

这很棒!

我无法直接回答您的问题,但从您的描述中,您似乎真的想要使用列表视图的虚拟模式来管理大型数据集。

http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.virtualmode.aspx