DataGridView。从单元格获取值时索引超出范围 [英] DataGridView . Index was out of range when getting value from a cell

查看:810
本文介绍了DataGridView。从单元格获取值时索引超出范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好家伙



i我收到此错误



指数超出范围。必须是非负数且小于集合的大小。

参数名称:index




hello guys

i am getting this error

"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"


private void ExcelDGV_CellClick(object sender, DataGridViewCellEventArgs e)
{
    if (e.RowIndex != -1)
    {
        textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
    }
}





任何帮助将不胜感激,谢谢



any help will be appreciated , thanks

推荐答案

这里有两种可能:

1)RowIndex超出范围,

2)单元格超出范围,



如果它不是RowIndex,那么它必须是Cell - 有没有?

或者...应该是dataGridView1在哪?方法名称暗示控件名为ExcelDGV ...



使用调试器查看行的各个部分,看看你有什么。
Two possibilities here:
1) RowIndex is out of the range,
2) Cells is out of the range,

If it isn't the RowIndex, then it has to be the Cells - are there any?
Or...should that be dataGridView1 at all? The method name implies the control is called ExcelDGV...

Use the debugger to look at the parts of the line and see what you do have.


这篇关于DataGridView。从单元格获取值时索引超出范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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