Sometimes, you will be programmatically changing tables or the number of rows, and binding them to an existing datagrid. If you have a higher page number selected when one of these changes happens, you will get a page count error like this:
Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount.
To fix this, do a Try/Catch error routine like this:
With MyDataGrid Try binddata ' where binddata is a databinding routine Catch .currentpageindex=0 binddata End Try end with