gauravghodnadikar
gauravghodnadikar

Reputation: 336

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.EndScroll) {}     
}

Upvotes: 1

Views: 1011

Answers (2)

Jan Lehmkuhl
Jan Lehmkuhl

Reputation: 1

You can use

if(e.Type == ScrollEventType.ThumbPosition)
// Do something

Upvotes: 0

Hans Passant
Hans Passant

Reputation: 942348

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.

Upvotes: 1

Related Questions