2 Attachment(s)
Index was out of range. Must be non-negative and less than the size of the collection
I want to populate a datagridview control with data from a database. The thing is that the datagridview has five columns but the last three are Read only because they populate based on the values of the first two. I'm getting an out of index error. Following is the code and an image of the DGV control and the error.
Code:
SQL.RunQuery("SELECT partNumber, lineQty FROM SERVICE_ORDER_LINE WHERE servNumber = '" & intValue & "' ")
' To verify there is data and that is correct
Dim debug1, debug3 As String
Dim debug2, debug4 As Integer
debug1 = SQL.SQLDS.Tables(0).Rows(0)(0)
debug2 = SQL.SQLDS.Tables(0).Rows(0)(1)
debug3 = SQL.SQLDS.Tables(0).Rows(1)(0)
debug4 = SQL.SQLDS.Tables(0).Rows(1)(1)
MsgBox(debug1)
MsgBox(debug2)
MsgBox(debug3)
MsgBox(debug4)
Dim var As Integer = SQL.SQLDS.Tables(0).Rows.Count - 1
MsgBox(var)
For i As Integer = 0 To var
For j As Integer = 0 To 1
frmServiceOrder.dgvPartsSO.Rows(i).Cells(j).Value = SQL.SQLDS.Tables(0).Rows(i)(j)
Next
Next
Attachment 120921Attachment 120923
Re: Index was out of range. Must be non-negative and less than the size of the collec
you only have 1 row in your dgv
Re: Index was out of range. Must be non-negative and less than the size of the collec
Yes because that is its starting size. All DGV start that way. Is there a way to make it display more rows before actually inserting any value???
Re: Index was out of range. Must be non-negative and less than the size of the collec
dgv.rows.add(number of rows)
Re: Index was out of range. Must be non-negative and less than the size of the collec
Re: Index was out of range. Must be non-negative and less than the size of the collec
Thanks a lot it worked...