Mi sono accorto che non andava perché non facevo di nuovo il bind, per cui il primo problema è ok. Però se sono all'ultima pagina e cancello l'ultimo record mi va in errore perché tenta di impostare una pagina superiore al PageCount del grid
Sub DataGrid_Delete(Sender As Object, E As DataGridCommandEventArgs)
' delete the selected row
If Not isEditing Then
'memorizza la pagina
dim pagina as integer
pagina= datagrid1.CurrentPageIndex
' the key value è l'ID della riga e cioè del record
Dim keyValue As String = CStr(DataGrid1.DataKeys(e.Item.ItemIndex))
' TODO: update the Command value for your application
Dim myConnection As New OledbConnection(ConnectionString)
Dim DeleteCommand As New OledbCommand("DELETE from Autore where idautore=" & keyValue , myConnection)
' execute the command
myConnection.Open()
DeleteCommand.ExecuteNonQuery()
myConnection.Close()
' rebind the grid
if pagina>datagrid1.PageCount-1 then
pagina=pagina-1
end if
datagrid1.CurrentPageIndex =Convert.ToInt32(pagina)
DataGrid1.EditItemIndex = -1
BindGrid()
End If
End Sub
![]()