DataGrid中删除最后一页的最后一条数据时CurrentPageIndex的问题

本文介绍了当在DataGrid中删除最后一页的最后一项数据时出现的“无效的CurrentPageIndex值”错误及其解决方案。提供了两种方法来避免此问题:一是通过检查当前页数并相应调整;二是使用try-catch结构来捕获异常并重置页面索引。
当删除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

 

转载于:https://www.cnblogs.com/bccu/archive/2006/11/09/555513.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值