我有一個winforms屏幕和Form_Activated事件中的下面的代碼。Winforms DataGridView單元格選擇更改提供了錯誤
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: 指定參數超出所述 有效值範圍的。參數名: columnIndex在 System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(的Int32 columnIndex,的Int32的rowIndex,布爾 setAnchorCellAddress,布爾 validateCurrentCell,布爾 throughMouseClick)在 System.Windows.Forms.DataGridView.SetSelectedCellCoreInternal(的Int32 columnIndex,的Int32 rowIndex位置,布爾 選擇的)在 System.Windows.Forms.DataGridViewCell.set_Selected(布爾 值)
什麼是genlGridIndex的價值? – 2011-05-04 03:39:33