DataGridView's ScrollEventType.EndScroll
How can I get ScrollEventType.EndScroll in dataGridView's Sroll event handlers method?
void dgvMapper_Scroll(object sender, ScrollEventArgs e)
{
if (e.Type == ScrollEventType.EndSc开发者_Python百科roll) {}
}
Most vertical scrolling in a DGV happens because the user is entering rows of data or pressing the up/down arrow keys on the keyboard. There is no "end-scroll" action for that. If that's not an issue, you can detect the user operating the scrollbar directly with this code:
using System;
using System.Windows.Forms;
class MyDataGridView : DataGridView {
public event EventHandler EndScroll;
protected void OnEndScroll(EventArgs e) {
EventHandler handler = EndScroll;
if (handler != null)
handler(this, EventArgs.Empty);
}
protected override void WndProc(ref Message m) {
base.WndProc(ref m);
if (m.Msg == 0x115) {
if ((ScrollEventType)(m.WParam.ToInt32() & 0xffff) == ScrollEventType.EndScroll) {
OnEndScroll(EventArgs.Empty);
}
}
}
}
Paste this in a new class. Compile. Drop the new control from the top of the toolbox onto your form.
You can use
if(e.Type == ScrollEventType.ThumbPosition)
// Do something
精彩评论