Scrolling within datagrid
Scrolling within datagrid
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:
---------------------------------------------------------------------------
Private Sub grdDataGrid_Scroll(...) Handles grdDataGrid.Scroll
Dim intShowAnzahl As Integer
Try
intShowAnzahl = dgcTopLeftVisibleCell.RowNumber + Me.grdDataGrid.VisibleRowCount
If intShowAnzahl = intSatzAnzahl Then
DataGridLoadNext()
End If
Catch ex As Exception
ErrorMessage(...)
End Try
End Sub
Private Sub DataGridLoadNext(Optional ByVal blnSetPoint As Boolean = False)
Dim intNewAnz As Integer
Dim intAktAnz As Integer
Try
If mblnFirst Then
mblnFirst = False
DataGridLoad()
Else
If intSatzAnzahl > 0 And intSatzAnzahl < objIBS_Query.lngMaxReadRecord Then
blnSatzAnzahlEnde = True
End If
If blnSatzAnzahlEnde = False Then
Me.Cursor = Windows.Forms.Cursors.WaitCursor
intAktAnz = Me.BindingContext(Me.DseDataSetPatient1, "KHSPET0").Count
intSatzAnzahl = intAktAnz
objIBS_Query.DataAdapterFillWaiting(objIBS_Query.dadDataAdapterPatient, Me.DseDataSetPatient1, intSatzAnzahl, CInt(objIBS_Query.lngMaxReadRecord), "KHSPET0")
DataGridFormat()
If blnSetPoint = True Then
If Me.grdDataGrid.RowCount > 0 Then 'hb130103
poiPointInCell00 = New Point(Me.grdDataGrid.GetCellBounds(0, 0).X + 4, Me.grdDataGrid.GetCellBounds(0, 0).Y + 4)
End If
End If
intNewAnz = Me.BindingContext(Me.DseDataSetPatient1, "KHSPET0").Count
If intAktAnz = intNewAnz Then
blnSatzAnzahlEnde = True
End If
If intSatzAnzahl > intNewAnz Then
blnSatzAnzahlEnde = True
End If
intSatzAnzahl = intNewAnz
Me.Cursor = Windows.Forms.Cursors.Default
Me.grdDataGrid.Refresh()
End If
End If
Catch ex As Exception
ErrorMessage(...)
Finally
End Try
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?