Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know whether the user is scrolling the datagridview

I wish to know whether a user is scrolling the DataGridView.

While the user is scrolling the DataGridView I wish to suspend a running thread and resume this thread as soon as the user stops scrolling.

Any help will be deeply appreciated from heart.

Thanks a lot :)

Update :

For my work regarding this,code is here :- Updating DataGridView via a thread when scrolling

like image 792
Ankush Roy Avatar asked Oct 05 '10 15:10

Ankush Roy


2 Answers

Please see here, this is an example using a ListView but it can easily be adapted to a DataGridView.

ListView onScroll event

like image 200
kyndigs Avatar answered Sep 28 '22 13:09

kyndigs


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);
                }            
        }
    }

Add your suspend code to Handler of the ScrollEvent event

like image 45
zabulus Avatar answered Sep 28 '22 13:09

zabulus