The index was out of bounds. It must not be negative and must be smaller than the size of the collection.

  • Thread starter Thread starter Bajtitou
  • Start date Start date
B

Bajtitou

Guest
Hi,

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."

This is My code:


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


End sub


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

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

Without the last line:


1419590.png



So thank you very Much.



Best Regards.

Continue reading...
 
Back
Top