该指数超出界限。它不能是负数,必须小于集合的大小。 [英] The index was out of bounds. It must not be negative and must be smaller than the size of the collection.

查看:496
本文介绍了该指数超出界限。它不能是负数,必须小于集合的大小。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误" 索引超出范围。它不能是负数,必须小于集合的大小。"

I get this Error " The index was out of bounds. It must not be negative and must be smaller than the size of the collection."

这是我的代码:

Private Sub ShowSevragesByCage() If Not String.IsNullOrEmpty(CmbCages.Text) Then _bsc2.DataSource = opsd.NetSevragesByCage(CmbCages.Text) Dgv.DataSource = _bsc2 Dgv.ExpandColumns() End If ' Sum Dim Sum As Integer = 0 For i As Integer = 0 To Dgv.Rows.Count - 1 - 1 Sum += Convert.ToInt32(Dgv.Rows(i).Cells(4).Value) Next

      Dgv(" NetDesSevrages",Dgv.Rows.Count - 1).Value = Sum

     Dgv("NetDesSevrages", Dgv.Rows.Count - 1).Value = Sum


End sub

End sub


<问题是在最后一行,而不是Sub运行。

The problem is in the last line , whithout it the Sub run .

  Dgv("NetDesSevrages", Dgv.Rows.Count - 1).Value = Sum




没有最后一行:


Without the last line:

非常感谢你。

最诚挚的问候。

推荐答案

尝试使用 

Try using 

Dim Test As Integer = Dgv.Rows.Count - 1

Dim Test As Integer = Dgv.Rows.Count - 1

在该行上设置断点以查看Test的值是什么。

Put a breakpoint on that line to see what the value of Test is.

对于i as Integer = 0 To Dgv .Rows.Count - 1 - 1

For i As Integer = 0 To Dgv.Rows.Count - 1 - 1

应该是

对于i as Integer = 0到Dgv.Rows.Count - 1 

For i As Integer = 0 To Dgv.Rows.Count - 1 


这篇关于该指数超出界限。它不能是负数,必须小于集合的大小。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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