Okay, I've run this before without a problem, but now I'm getting a warning stating "InvalidArgument=Value of '1' is not valid for 'index'.
Parameter name: index".
Why would it begin giving me this error now after running it in debug several times without a problem before
Anyone, please help.

I've run this before without a problem, but now I'm getting a warning!
TomEire
manu.aretuseo
Steev
Jim Perry
Hi,
The error message sounds like you are getting an IndexOutOfRange exception, or something similar. Chances are you are trying to access an array or collection with an invalid index.
You might want to check that the collection you are accessing actually has data in it (look at the length field or Count property). Also, in VB.NET array indicies are 0-based, not 1-based, so the index of the first element in an array is 0, not 1.
-Scott Wisniewski
wvvjoevvw
I forgot to include the code, here it is. The line in yellow is what keeps poping up the warning during debugging.
Private
Sub DeleteButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteButton.Click 'Check which item has been selected' Dim Count As Integer = Me.ListView1.Items.Count Dim AddFromZero As Integer = 0 While AddFromZero <= Count If ListView1.Items(AddFromZero).Selected = True Then Dim SelectedDataRow = Me.Child_Information_DatabaseDataSet.Child_Information.Rows(AddFromZero)("FirstName") + " " + Me.Child_Information_DatabaseDataSet.Child_Information.Rows(AddFromZero)("LastName") Dim answer As DialogResultanswer = MessageBox.Show(
"Are you sure you want to delete " + SelectedDataRow + " from the database ", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) If answer = vbYes Then 'Delete the selected database' Me.Child_Information_DatabaseDataSet.Child_Information.Rows(AddFromZero).Delete() 'Update changes to the database' Me.Child_InformationTableAdapter.Update(Me.Child_Information_DatabaseDataSet.Child_Information) Me.Child_Information_DatabaseDataSet.Child_Information.AcceptChanges() 'Clear the ListView and re-populate it with any updates of the database.' Me.ListView1.Clear()Child_Information_DatabaseDataSet.EnforceConstraints =
False Me.Child_InformationTableAdapter.Fill(Me.Child_Information_DatabaseDataSet.Child_Information) For Each CurrentRow As DataRow In Me.Child_Information_DatabaseDataSet.Child_Information Me.ListView1.Items.Add(CurrentRow.Item("FirstName") + " " + (CurrentRow.Item("LastName")), 0) Next End If End IfAddFromZero = AddFromZero + 1
End While End Subjapt
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=507280&SiteID=1
Lil endian
Either subtract one from Count or change:
While AddFromZero <= Count
to
While AddFromZero < Count
The reason is because the list is Zero based.
hrubesh
beefeater
cool, thanks. this is what I added to my code and it works fine now. Thanks for spotting that....
Private
Sub DeleteButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteButton.Click 'Check which item has been selected' Dim Count As Integer = Me.ListView1.Items.Count Dim AddFromZero As Integer = 0 While AddFromZero < Count If ListView1.Items(AddFromZero).Selected = True Then Dim SelectedDataRow = Me.Child_Information_DatabaseDataSet.Child_Information.Rows(AddFromZero)("FirstName") + " " + Me.Child_Information_DatabaseDataSet.Child_Information.Rows(AddFromZero)("LastName") Dim answer As DialogResultanswer = MessageBox.Show(
"Are you sure you want to delete " + SelectedDataRow + " from the database ", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) If answer = vbYes Then 'Delete the selected database' Me.Child_Information_DatabaseDataSet.Child_Information.Rows(AddFromZero).Delete() 'Update changes to the database' Me.Child_InformationTableAdapter.Update(Me.Child_Information_DatabaseDataSet.Child_Information) Me.Child_Information_DatabaseDataSet.Child_Information.AcceptChanges() 'Clear the ListView and re-populate it with any updates of the database.' Me.ListView1.Clear()Child_Information_DatabaseDataSet.EnforceConstraints =
False Me.Child_InformationTableAdapter.Fill(Me.Child_Information_DatabaseDataSet.Child_Information) For Each CurrentRow As DataRow In Me.Child_Information_DatabaseDataSet.Child_Information Me.ListView1.Items.Add(CurrentRow.Item("FirstName") + " " + (CurrentRow.Item("LastName")), 0) Next End If End IfCount =
Me.ListView1.Items.CountAddFromZero = AddFromZero + 1
End While End Sub