Start New Discussion within our Software Development Community

Dear Experts

Table gpass has data as

Then there are two textbox having values as


I these codes and it generates error message as

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

What mistake I am doing, please modify

Private Sub txtGat_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtGat.TextChanged
        If Len(Me.txtGat.Text) > 0 AndAlso Me.txtDat.Text IsNot Nothing Then

            str = "Select * from gpass where vou_no= " & Val(Me.txtGat.Text) & " And Date =   '" & Me.txtDat.Text & "'"
            dt = GetTable(str)

            If (dt.Rows.Count > 0) Then
                Me.txtCir.Text = dt.Rows(0)("c")
                Me.txtVou.Text = dt.Rows(0)("bno")

            End If

            For i = 0 To dt.Rows.Count -1
                Me.DataGridView1.Rows(i).Cells(0).Value = Val(dt.Rows(i).Item(1))
                Me.DataGridView1.Rows(i).Cells(1).Value = Trim(dt.Rows(i).Item(2))
                Me.DataGridView1.Rows(i).Cells(2).Value = Val(dt.Rows(i).Item(3))
                Me.DataGridView1.Rows(i).Cells(3).Value = Val(dt.Rows(i).Item(4))

        End If
    End Sub

would you please the next time you have an error msg just tell the number of line it's shown on

anyways ......... from the code you provided the msg could be raised at the line number 17

make sure that the DataGridView has Columns already added ,
or you can assign the DataTable to DataGridView.DataSource,
this would make your life easier

Me.DataGridView1.DataSource = dt

hope this helps

This article has been dead for over six months. Start a new discussion instead.