如何修复VScrollBar_Scroll()错误 [英] How to fix VScrollBar_Scroll() Error

查看:144
本文介绍了如何修复VScrollBar_Scroll()错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试下面的代码时:

private void vScrollBar1_Scroll(object sender,ScrollEventArgs e)

{

dgvItem.FirstDisplayedScrollingRowIndex = vScrollBar1 .Value;

}



我收到如下错误:

指定参数超出范围有效值。

参数名称:值

如何修复此错误。请帮助我。

谢谢

When i try code as below:
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
dgvItem.FirstDisplayedScrollingRowIndex = vScrollBar1.Value;
}

I Get error as below :
"Specified argument was out of the range of valid values.
Parameter name: value "
how to fix this error. Please help me.
Thanks

推荐答案

正如Bill所说,调试器是你最好的选择 - 但我想你会发现问题非常简单:VScrollBar的Value属性不会自动链接到DataGridView,因此它介于最小值和最大值之间,而不受DGV中行数的限制。因此,当您滚动时,您会得到0到100之间的数字(最小值和最大值的默认值),如果您的DGV只有十行,您将很快收到错误...



将Maximum属性设置为行数(减1),它应该没问题。
As Bill says, the debugger is your best bet here - but I think you will find that the problem is pretty simple: The Value property of the VScrollBar is not automatically linked to the DataGridView, so it ranges between the Minimum and Maximum values, instead of being limited by the number of rows in the DGV. So when you scroll, you get a number between 0 and 100 (the defaults for Minimum and Maximum) and if your DGV has only ten row, you will get an error very quickly...

Set the Maximum property to the number of rows (minus one) and it should be fine.


这篇关于如何修复VScrollBar_Scroll()错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆