我想知道用戶是否滾動DataGridView。如何知道用戶是否滾動datagridview
當用戶滾動DataGridView時,我希望暫停正在運行的線程,並在用戶停止滾動時立即恢復此線程。
任何幫助將從心中深深感激。
感謝很多:)
更新:
對於我關於這項工作,代碼是在這裏: - Updating DataGridView via a thread when scrolling
我想知道用戶是否滾動DataGridView。如何知道用戶是否滾動datagridview
當用戶滾動DataGridView時,我希望暫停正在運行的線程,並在用戶停止滾動時立即恢復此線程。
任何幫助將從心中深深感激。
感謝很多:)
更新:
對於我關於這項工作,代碼是在這裏: - Updating DataGridView via a thread when scrolling
public class DataGridViewEx : DataGridView
{
private const int WM_HSCROLL = 0x0114;
private const int WM_VSCROLL = 0x0115;
private const int WM_MOUSEWHEEL = 0x020A;
public event ScrollEventHandler ScrollEvent;
const int SB_HORZ = 0;
const int SB_VERT = 1;
public int ScrollValue;
[DllImport("User32.dll")]
static extern int GetScrollPos(IntPtr hWnd, int nBar);
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_VSCROLL ||
m.Msg == WM_MOUSEWHEEL)
if (ScrollEvent != null)
{
this.ScrollValue = GetScrollPos(Handle, SB_VERT);
ScrollEventArgs e = new ScrollEventArgs(ScrollEventType.ThumbTrack, ScrollValue);
this.ScrollEvent(this, e);
}
}
}
添加您的暫停代碼的表示ScrollEvent事件
感謝您的回答。我已upvoted yor回答。但我是一個新手編碼器,並不能得到在哪裏添加此代碼善意幫助....這是我的代碼: - http://stackoverflow.com/questions/3766784/problem-in-更新datagridview通過一個線程時滾動。請讓我知道在哪裏實現這個代碼,如果你可以提供演示它會很棒...... – 2010-10-08 15:18:56
你需要創建新的分類項目和粘貼我的代碼片段。然後在你的窗體的設計器中改爲DataGridView datagrid = new DataGridView();你必須寫下:DataGridView datagrid = new DataGridViewEx(); – zabulus 2010-10-09 15:59:21
請在這裏看到,這是一個使用ListView控件的例子,但它可以很容易地適應DataGridView。
+1我已經學到了一些新的東西給你的鏈接! – 2010-10-05 15:31:54
感謝您的回答。我已upvoted yor回答。但我是一個新手編碼器,並不能得到在哪裏添加此代碼善意幫助....這是我的代碼: - http://stackoverflow.com/questions/3766784/problem-in-更新datagridview通過一個線程時滾動。請讓我知道在哪裏實現這個代碼,如果你可以提供演示它會很棒...... – 2010-10-08 15:16:24
+1我從來沒有需要作用於滾動事件到目前爲止的處理程序,但如果我這樣做有一天,你的問題很可能是鑑於其答案是有用的。 – 2010-10-05 15:33:07