I have a datagrid with its DataSource set to a dataset.

The first time the user clicks on the button "show" 25 records are read.

Now I need the following functionality:
If the user scrolls down and the last record is reached, the next 25 records should be read.

This is how I tried to do it:

VB Code:
  1. Private Sub grdDataGrid_Scroll(...) Handles grdDataGrid.Scroll
  2.     Dim intShowAnzahl As Integer
  3.     Try
  4.         intShowAnzahl = dgcTopLeftVisibleCell.RowNumber + Me.grdDataGrid.VisibleRowCount
  5.         If intShowAnzahl = intSatzAnzahl Then
  6.             DataGridLoadNext()
  7.         End If
  8.     Catch ex As Exception
  9.         ErrorMessage(...)
  10.     End Try
  11. End Sub
  12.  
  13. Private Sub DataGridLoadNext(Optional ByVal blnSetPoint As Boolean = False)
  14.     Dim intNewAnz As Integer
  15.     Dim intAktAnz As Integer
  16.     Try
  17.         If mblnFirst Then
  18.             mblnFirst = False
  19.             DataGridLoad()
  20.         Else
  21.             If intSatzAnzahl > 0 And intSatzAnzahl < objIBS_Query.lngMaxReadRecord Then
  22.                 blnSatzAnzahlEnde = True
  23.             End If
  24.             If blnSatzAnzahlEnde = False Then
  25.                 Me.Cursor = Windows.Forms.Cursors.WaitCursor
  26.                 intAktAnz = Me.BindingContext(Me.DseDataSetPatient1, "KHSPET0").Count
  27.                 intSatzAnzahl = intAktAnz
  28.                 objIBS_Query.DataAdapterFillWaiting(objIBS_Query.dadDataAdapterPatient, Me.DseDataSetPatient1, intSatzAnzahl, CInt(objIBS_Query.lngMaxReadRecord), "KHSPET0")
  29.                 DataGridFormat()
  30.                 If blnSetPoint = True Then
  31.                     If Me.grdDataGrid.RowCount > 0 Then 'hb130103
  32.                         poiPointInCell00 = New Point(Me.grdDataGrid.GetCellBounds(0, 0).X + 4, Me.grdDataGrid.GetCellBounds(0, 0).Y + 4)
  33.                     End If
  34.                 End If
  35.                 intNewAnz = Me.BindingContext(Me.DseDataSetPatient1, "KHSPET0").Count
  36.                 If intAktAnz = intNewAnz Then
  37.                     blnSatzAnzahlEnde = True
  38.                 End If
  39.                 If intSatzAnzahl > intNewAnz Then
  40.                     blnSatzAnzahlEnde = True
  41.                 End If
  42.                 intSatzAnzahl = intNewAnz
  43.                 Me.Cursor = Windows.Forms.Cursors.Default
  44.                 Me.grdDataGrid.Refresh()
  45.             End If
  46.         End If
  47.     Catch ex As Exception
  48.         ErrorMessage(...)
  49.     Finally
  50.     End Try
  51. End Sub

Sometimes this works fine. But sometimes it seems that the scroll event is fired again and again.
Or in some other cases I only get an hourglass and nothing happens.

Any idea what I may have forgotten?