¿Indice Fuera de Rango?

Que tal,

Tengo un problema lo que pasa es que estoy haciendo unas modificaciones en .net y bueno estoy haciendo que mediante un botón se anule documento masivamente, pero en mi for me sale este error :

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

Adjunto código

Private Sub EliminarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EliminarToolStripMenuItem.Click
Dim IntContador As Integer = 0
Dim i As Integer
Dim idTarifaCarga As String
For i = 0 To DgvTarifario.Rows.Count - 1
If DgvTarifario.Rows(i).Cells(0).Value Then
IntContador += 1
End If
Next
If IntContador = 0 Then
MsgBox("Debe marcar al menos un documento", MsgBoxStyle.Exclamation, "Aviso")
Exit Sub
End If
If DgvTarifario.RowCount <> 0 Then
For i = 0 To DgvTarifario.RowCount - 1
If DgvTarifario.Rows(i).Cells("ChekMasivo").Value Then
idTarifaCarga = DgvTarifario.Rows(i).Cells("NRO_TAR").Value
Try
If (MessageBox.Show("Está Seguro que desea Anular la Tarifa ", "Confirmar", MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button2) = DialogResult.Yes) Then
Dim dtResultado As DataTable
ObjTarifaPublica_LN = New Cls_TarifaPublica_LN
Dim ip As String
Dim Usuario As String
ip = dtoUSUARIOS.IP
Usuario = dtoUSUARIOS.IdLogin
dtResultado = ObjTarifaPublica_LN.AnularTarifa_LN(idTarifaCarga, ip, Usuario)
Button1_Click(sender, e)
Else
Button1.Focus()
End If
Catch ex As Exception
Throw ex
End Try
End If
Next
MsgBox("Se Anularon Satisfactoriamente", MsgBoxStyle.Information, "Aviso")
End If
End Sub

Quisiera saber por que me sale ese error, gracias espero puedas ayudarme.

1 Respuesta

Respuesta

En q linea te genera el error

Deberias meter dentro del try las condiciones y los ciclos

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas