0

This is my first SO question, so please direct me if I have made any mistakes.

I am new to C# programming and am self-teaching. I have been able to find lots of information similar to my problem (delaying code), but I am unable to find/extract a solution to my specific problem. I have tried searching, but perhaps with the wrong keywords... In addition, despite re-reading and searching, sometimes answers are too advanced for me to discern; perhaps I've read my solution but didn't realize it.

Here's my setup and subsequent problem:

I have a DataGridView that displays data from a SQL Server database that will be accessed over the internet (I'm developing/testing over a LAN at the moment). When the user selects a new line in the DGV, the rest of the form populates with information based on that record, and this process happens quickly enough.

However, if the user scrolls through the list (using the arrow keys), the data is refreshed over and over again while they scroll, which slows the application down. In addition, it seems unnecessary to me to query the server for each row either (there will be many users, but not thousands yet) .

I think that my solution is to delay the execution of the code that populates the rest of the form until the user lands on the row that they want. So, wait until they've had the same row selected for, say, 1 second.

The answers I have found so far all seem to effectively set a code "time bomb" that will always execute after the specified delay. I need to delay my code, but then only execute it if the user is still on the same row as they were when the delay was initiated.

Can anyone point me in the right direction? Or am I approaching this the wrong way? If you would, please try to phrase an answer such that a beginner can either understand it or use keywords that can be looked up.

I'm sure I'm not the first person to have this problem- surely there's some kind of best-practices approach to using the DGV and using it for this purpose? However, searching SO for "c# datagridview scroll delay code" or "c# datagridview selectionchanged delay" returns no results, and other searches have proven unfruitful.

Details that my be needed or asked for:

  • This is a C# Windows Forms Application.
  • I'm using Visual Studio 2012.
  • The code updating the form is within the DGV's SelectionChanged event code block.
3
  • I suggest you to check throttle from reactive framework c# or check this post : stackoverflow.com/questions/21400514/… Jan 4, 2016 at 21:09
  • Whats wrong with using a timer? when it reaches its timeout of 1 second, you inititate the data request or else you reset the timer and start it again.
    – Sievajet
    Jan 4, 2016 at 22:08
  • Can the timer be interrupted? For instance, if the user scrolls down from row 1 to row 3, what happens to the timer started when row 2 was entered (and then "immediately" exited)? Can each SelectionChanged event be used to reset an existing timer and then wait to see if the appropriate amount of time has elapsed?
    – elmer007
    Jan 4, 2016 at 22:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.