How to prevent error in datagrid

G

Guest

Hi all,
I have problem in auto scroll to previous page when i try to delete the last
row of the datagrid.

The problem scenario is:
1.I click on next page of the datagrid.
2.I delete all the data in the page.
3.When i try to delete the last row, the error happen.

The error message:
Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount.

The code that cause the error is at datagrid.databind()
How to solve it??

Any ideas?
thank you in advance.
Best regards,
Gin Lye Khor
 
G

Guest

Hi Gin,

Keep a counter of the number of rows deleted (iNoOfRecordsDeleted). If you
delete a page then the no. of deleted rows is the DataGrid.PageSize. Then
before you rebind the grid, check for the CurrentPageIndex:

If iNoOfRecordsDeleted = datagrid1.PageSize AndAlso _
datagrid1.CurrentPageIndex = datagrid1.PageCount - 1 Then
datagrid1.CurrentPageIndex -= 1
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top