检测用户是否正在滚动dataGridView滚动条 [英] Detect if user is scrolling dataGridView scrollbar
本文介绍了检测用户是否正在滚动dataGridView滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用新的DataTable更新 dataGridView
I am updating a dataGridView
with a new DataTable using
dataGridView1.DataSource = table
但是,当用户滚动浏览器时,我不想这样做dataGridView。如何检查滚动条是否正在滚动或已完成滚动(即拖动而不是单击)?
However, I don't want to do this when a user is scrolling the dataGridView. How do I check if the scrollbar is being scrolled or completed scrolling (ie dragging rather than clicking)?
我看过Scroll事件,但似乎第一次单击滚动条并完成滚动条时触发。
I've had a look at the Scroll event but it only seems to trigger when the scrollbar is first clicked and not completed. A Google search doesn't seem to bring up much specific to this either.
推荐答案
我以前是这样做的
public class DataGridViewEx : DataGridView
{
public bool IsUserScrolling { get; private set; }
private const int WM_HSCROLL = 0x0114;
private const int WM_VSCROLL = 0x0115;
private const int SB_ENDSCROLL = 8;
public event EventHandler UserScrollComplete;
protected virtual void OnUserScrollComplete()
{
EventHandler handler = UserScrollComplete;
if (handler != null) handler(this, EventArgs.Empty);
}
protected override void WndProc(ref Message m)
{
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb787575(v=vs.85).aspx
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb787577(v=vs.85).aspx
if ((m.Msg == WM_HSCROLL) ||
(m.Msg == WM_VSCROLL))
{
short loword = (short)(m.WParam.ToInt32() & 0xFFFF);
if (loword == SB_ENDSCROLL)
{
IsUserScrolling = false;
OnUserScrollComplete();
}
else
{
IsUserScrolling = true;
}
}
base.WndProc(ref m);
}
}
这篇关于检测用户是否正在滚动dataGridView滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文