views:

54

answers:

1

How can i get ScrollEventType.EndScroll in dataGridView's Sroll event handlars mehtod.

      void dgvMapper_Scroll(object sender, ScrollEventArgs e)    
     {        
          if (e.Type == ScrollEventType.EndScroll)        
         {}     
     }
A: 

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.

Hans Passant