当删除DataGrid中最后一页,最后一条数据时会出现下面的错误:

无效的 CurrentPageIndex 值。它必须大于等于 0 且小于 PageCount

解决办法:
1、
If DataGrid2.Items.Count Mod DataGrid2.PageSize = NumberOfItemsChecked And _
DataGrid2.CurrentPageIndex = DataGrid2.PageCount - 1 And _
DataGrid2.CurrentPageIndex <> 0 Then
DataGrid2.CurrentPageIndex = DataGrid.CurrentPageIndex - 1
End If

2、

try
'Bind the Data
catch ex as ArgumentOutOfRangeException
DataGrid1.CurrentPageIndex = 0;
'Bind the Data
end try