日期:2014-05-17  浏览次数:20840 次

索引超出范围 问题
  private void dgvInventoryAccount_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int iRow = dgvInventoryAccount.CurrentCell.RowIndex;
            if (iRow >= 0)
            {
                string userID = dgvInventoryAccount.SelectedRows[iRow].Cells["UserID"].Value.ToString();
                DataSet dsTask = InventoryManager.GetInventoryTaskList(userID);
                ShowInventoryTask(dgvInventoryTask, dsTask);
            }

        }


 string userID = dgvInventoryAccount.SelectedRows[iRow].Cells["UserID"].Value.ToString();  这一行一直提示  索引超出范围。必须为非负值并小于集合大小。 请问各位大侠该怎么修改好??谢谢

------解决方案--------------------
直接用这个:this.dataGridView1.CurrentCell.Value.ToString();