9

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

Community
  • 1
  • 1
Ankush Roy
  • 1,621
  • 2
  • 15
  • 25
  • +1 I have never needed to act on scrolling events so far, but if I do someday, your question is likely to be useful given its answer(s). – Will Marcouiller Oct 05 '10 at 15:33

2 Answers2

3

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

ListView onScroll event

Community
  • 1
  • 1
kyndigs
  • 3,074
  • 1
  • 18
  • 22
  • Thanks for your answer. I have upvoted yor answer.But I am a novice coder and couldn't get where to add this code kindly help....Here is my code :- http://stackoverflow.com/questions/3766784/problem-in-updating-datagridview-via-a-thread-when-scrolling .Please let me know where to implement this code and if you can provide demo it would be great...... – Ankush Roy Oct 08 '10 at 15:16
2
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

zabulus
  • 2,373
  • 3
  • 15
  • 27
  • Thanks for your answer. I have upvoted yor answer.But I am a novice coder and couldn't get where to add this code kindly help....Here is my code :- http://stackoverflow.com/questions/3766784/problem-in-updating-datagridview-via-a-thread-when-scrolling .Please let me know where to implement this code and if you can provide demo it would be great...... – Ankush Roy Oct 08 '10 at 15:18
  • 1
    You need to create new classin your project and paste my code snippet to it. Then in designer of your form instead DataGridView datagrid = new DataGridView(); you must write next: DataGridView datagrid = new DataGridViewEx(); – zabulus Oct 09 '10 at 15:59