【发布时间】:2011-05-03 19:49:43
【问题描述】:
我在 Form_Activated 事件中有一个 winforms 屏幕和以下代码。
if (genlGrid1.Rows.Count > 0 && genlGrid1.Rows.Count <= genlGridIndex + 1 && (genlGridIndex >= 0 && genlGridIndex < 2))
{
//Looks like below line is where exception occurs
genlGrid1.Rows[genlGridIndex].Cells[0].Selected = true;
}
我很确定当这行代码执行时网格有2行9个单元格。
当执行这行代码时,我收到以下错误。不知道网格发生了什么。什么是 SetCurrentCellAddressCore,为什么会出现此异常?
有人可以帮忙吗?
System.ArgumentOutOfRangeException: 指定的参数超出了 有效值的范围。参数名称: 列索引在 System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, 布尔值 setAnchorCellAddress,布尔值 验证CurrentCell,布尔值 通过鼠标单击)在 System.Windows.Forms.DataGridView.SetSelectedCellCoreInternal(Int32 columnIndex, Int32 rowIndex, 布尔值 选择)在 System.Windows.Forms.DataGridViewCell.set_Selected(布尔 值)
【问题讨论】:
-
genlGridIndex 的值是多少?
标签: winforms datagridview selection