InvalidArgument=Value of '-1' is not valid for 'index'. Parameter name: index

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi All,

Im new to MySQL, I have a program (VB.NET 2010) wherein I have a text box and when I press enter it will query the DB and display results in a DataGridView. But I am getting an error after pressing the Enter key :

InvalidArgument=Value of -1 is not valid for index.
Parameter name: index

Heres the code:
Public Sub SearchByName(ByVal name As String)

dgvInfo.ClearSelection()
lstNames.ClearSelected()

Dim dgvRow As DataGridViewRow = _
(From row As DataGridViewRow In dgvInfo.Rows
Where row.Cells("colName").Value.ToString().ToUpper().Contains(name.ToUpper())
Select row).FirstOrDefault()

If Not dgvRow Is Nothing Then
dgvRow.Selected = True
dgvInfo.FirstDisplayedScrollingRowIndex = dgvRow.Index
dgvInfo.PerformLayout()
End If

Dim index = lstNames.FindString(name)
lstNames.SetSelected(index, True)
End Sub
Im a newbie, any help will be appreciated

View the full article
 
Back
Top