当ListView的滚动条到达的WinForms底部检测 [英] Detecting when ListView scrollbar reaches the bottom in WinForms
问题描述
我怎么知道什么时候的WinForms ListView的滚动条到达它的底部? 当发生这种情况,我想在ListView被填充更多的数据(这是无止境的理论在我的情况)。
How do I know when the WinForms ListView scrollbar reaches it's bottom ? When this happens, I want the listview to be populated with more data (which is endless in theory in my case).
在OnScroll事件让我从上面滚动的价值,但我没有办法知道,如果用户可以在任何进一步的或不滚动的。
The OnScroll event gives me the scroll value from the top, but I have no way of knowing if the user can scroll any further or not.
推荐答案
我找到了答案使用一些code从大ObjectListView code-项目: HTTP://www.$c$cproject.com/KB/list/ObjectListView的.aspx
I found an answer using some code from the great ObjectListView code-project: http://www.codeproject.com/KB/list/ObjectListView.aspx
调用GetScrollInfo:
call 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);
[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;
}
这个数据结构:
with this data struct:
[StructLayout(LayoutKind.Sequential)]
public class SCROLLINFO
{
public int cbSize = Marshal.SizeOf(typeof(NativeMethods.SCROLLINFO));
public int fMask;
public int nMin;
public int nMax;
public int nPage;
public int nPos;
public int nTrackPos;
}
在nMax分别给出了总的最大滚动值,包括滚动柄本身,所以真正有用的最大值为n最大 - n页面,其中n页面的滚动柄的大小
the nMax gives the total max scroll value including the scroll handle itself, so the actually useful max value is nMax - nPage, where nPage is the size of the scroll handle.
这个伟大的工程!
这篇关于当ListView的滚动条到达的WinForms底部检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!