473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to prevent error in datagrid

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

Nov 20 '05 #1
1 1287
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

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Daniel" wrote:
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

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jim Bayers | last post by:
I have a simple page, all that's on it is a datagrid. The datagrid is populated on page_load when it is bound to a datareader. The problem is: when a user refreshes the page, new records are...
1
by: Brian | last post by:
Hello - Is there a way to prevent the user from creating a blank row at the bottom of a datagrid? I want a read only grid that allows the user to view data but not select specific cells or...
2
by: Tor Inge Rislaa | last post by:
Prevent Adding new records in DataGrid Hi I have a DataGrid that I want to open for editing but the user should not be able to add new records. When I set the ReadOnly = False it is possible...
10
by: mttc | last post by:
I read articles that suggest preventing delete by throwing Exception from RowDeleting Event. I not understand where I can catch this Error?
5
by: Maria Anthonsen | last post by:
I have filled a datagrid with data from a dataset. The dataset was filled with a dataadapter - and I used the wizard to create insert, update, delete commands. I would like to prevent the user...
4
by: Rich | last post by:
I fill a dataset like this: dim da As New SqlDataAdapter, ds As New Dataset, conn As New SqlConnection .... da.Fill(ds, "tbl1") datagrid1.DataSource = ds datagrid1.DataMember = "tbl1" When...
3
by: Ryan Liu | last post by:
Can someone give a sample to prevent a row from being deleted in a datatable? I tried e.Row.RejectChanges(); in dt_RowDeleting() but seems does not work. I need verify if there other data...
5
by: Sharon | last post by:
I have a DataGrid on my Form, and I wish to disable any cell editing. For example; when the user clicks on a cell, the cell become editable by changing its color to gray and context menu is shown...
0
by: prerak_v_shah | last post by:
Hi, Friends, I have been developing datagrid program in .Net 1.1 and having VB.Net as a programming language. I have created a datagrid which is bound to a datatable as its datasource. It also...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.