title: How to scroll until it hits the bottom, then reset to top?
body: <p>Using <code>Winforms</code>, I have a <code>Datagridview</code> populated by data from my database. I refresh the <code>datagridview</code> every 5 seconds to reflect any changes made in my database.</p>
  
  <p>I'd like to know how to scroll down a bit each time I refresh the <code>datagridview</code> until it hits the bottom. When it reaches the bottom, I'd like to reset the scroll back to the top.</p>
  
  <p>Currently I have this code:</p>
  
  <pre><code>if(scrollPosition &lt; dataGridView1.RowCount - 1 - 5)
  {
      scrollPosition+=5;
  }
  
  else
  {
      // the scroll value has already exceeded, reset to 0
      scrollPosition = 0;
  }
  dataGridView1.FirstDisplayedScrollingRowIndex = scrollPosition;
  </code></pre>
  
  <p>The default value of my scrollPosition is 0 by the way</p>
  
  <p>It scrolls down properly but it doesn't seem to reset back to the top. It doesn't go through my second if statement. I know I'm just missing some logic here. What am I doing wrong?</p>
  
  <p>Update: Got it to work with the answer of huangda, and also updated my current code above, but it still seems buggy. There are times where it reaches the bottom already, but it doesn't scroll back to the top. I sometimes need to wait around 1 to 5 "+=5" more increments and then it will scroll to top aka fire the else statement.</p>
  
  <p>I'd like to ask a follow up question. Is using dataGridView1.RowCount really the way to go in this situation? Or is there something better I could use to compare my scrollPosition with?</p>