如何获取datagridview的最后一行值 [英] How to get the datagridview last row value

查看:60
本文介绍了如何获取datagridview的最后一行值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们......



这里我想获取数据网格视图的最后一行值



i尝试这样,

Hi Friends...

Here i want to get the data grid view last rows value

i tried like this,

txtid.Text =dataGridView1.Rows[dataGridView1.RowCount].Cells[348].Value.ToString;



它给出错误



指数超出范围。必须是非负数且小于集合的大小。参数名称:索引





我没有得到什么问题,



请帮帮我...



提前谢谢..


it gives error

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


what is the problem i am not getting,

please help me...

thanks in advance..

推荐答案

试试这样..







Try like this..



txtid.Text =dataGridView1.Rows[dataGridView1.Rows.Count -1 ].Cells[348].Value.ToString;


您正在使用dataGridView1.RowCount,它将返回总行数。现在,假设值348是正确的,请记住,在尝试从集合中获取值时,如下所示,其索引为零,可以按如下方式访问最后一个值:



You're using dataGridView1.RowCount which will return the total count of rows. Now, assuming that the value 348 is correct, always remember that while trying to fetch a value from a collection, like this, whose index are zero based, the last value can be accessed as follows:

txtid.Text =dataGridView1.Rows[(dataGridView1.RowCount  - 1)].Cells[348].Value.ToString;







对于收藏中的ex,长度为10的ABC,如果你写ABC [ABC.Length],则意味着你想要访问不存在的集合的第11个索引,因此出现此错误。




For ex in a collection, ABC of length 10, if you write ABC[ABC.Length], it means you're tring to access the 11th index of the collection which is not there, hence this error.


这篇关于如何获取datagridview的最后一行值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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