InvalidArguement=Value of '0' is not valid for 'index'.Parameter name index

I decided to put all classes in the same project. so I got rid of errors but now when I click a button to load a listview control. I get
after button click I get this message box this here is code
DB Connection
Imports System.Data.SqlClient
Public Class DB
    Public Shared Function GetConnection() As SqlConnection
        Dim connectionString As String =
            "Persist Security Info=False;User ID=sa;Password=50Cent;Initial Catalog=TSN2;Server=tsnappdev01"
        Return New SqlConnection(connectionString)
    End Function
End Class

Open in new window


here is form code

Public Class Form1
    Public Sub FormatLVStatus()
        'lvHotfixes.Location = New System.Drawing.Point(13, 54)
        lvPlayers.Margin = New System.Windows.Forms.Padding(4)
        lvPlayers.MultiSelect = False
        lvPlayers.Name = "LVCONNECT1"

        'LVCONNECT.TabIndex = 7
        lvPlayers.UseCompatibleStateImageBehavior = True
        lvPlayers.View = System.Windows.Forms.View.Details
        lvPlayers.Columns.Add("", 25, HorizontalAlignment.Left)
        lvPlayers.Columns.Add("PlayerID", 100, HorizontalAlignment.Left)
        lvPlayers.Columns.Add("Firstname", 150, HorizontalAlignment.Left)
        lvPlayers.Columns.Add("Lastname", 150, HorizontalAlignment.Left)
        lvPlayers.Columns.Add("Position", 150, HorizontalAlignment.Left)
        lvPlayers.Columns.Add("Height", 150, HorizontalAlignment.Left)
        lvPlayers.Columns.Add("Weight", 150, HorizontalAlignment.Left)

    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        FormatLVStatus()
    End Sub

    Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click
        Dim playersList As List(Of Players)
        Try
            playersList = PlayersSQL.GetPlayers
            If playersList.Count > 0 Then
                Dim players As Players
                For i As Integer = 0 To playersList.Count - 1
                    players = playersList(i)
                    '  lvPlayers.Items.Add(players.playersNumber)
                    lvPlayers.Items(i).SubItems.Add(
                        CInt(players.PlayerID).ToString)
                    lvPlayers.Items(i).SubItems.Add(
                        CStr(players.Firstname))
                    lvPlayers.Items(i).SubItems.Add(
                        CStr(players.Lastname))
                    lvPlayers.Items(i).SubItems.Add(
                        CStr(players.Position))
                    lvPlayers.Items(i).SubItems.Add(
                        CStr(players.Height))
                    lvPlayers.Items(i).SubItems.Add(
                        CStr(players.Weight))
                Next
            Else
                MessageBox.Show("All playerss are paid in full.",
                    "No Balance Due")
                Me.Close()
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, ex.GetType.ToString)
            Me.Close()
        End Try
    End Sub
End Class

Open in new window


PlayersSQL

Imports System.Data.SqlClient
Public Class PlayersSQL
    Public Shared Function GetPlayers() As List(Of Players)
        Dim playersList As New List(Of Players)
        Dim connection As SqlConnection = DB.GetConnection
        Dim selectStatement As String =
            "SELECT PlayerID, Firstname, Lastname, " &
             "Position, Weight, Height " &
             "FROM NFLPlayers " &
             "ORDER BY Lastname"
        Dim selectCommand As New SqlCommand(selectStatement, connection)
        Try
            connection.Open()
            Dim reader As SqlDataReader =
                selectCommand.ExecuteReader()
            Dim players As Players
            Do While reader.Read
                players = New Players
                players.PlayerID = CInt(reader("playerID"))
                players.Firstname = CStr(reader("firstname"))
                players.Lastname = CStr(reader("lastname"))
                players.Position = CStr(reader("position"))
                players.Height = CStr(reader("height"))
                players.Weight = CStr(reader("weight"))
                playersList.Add(players)
            Loop
            reader.Close()
        Catch ex As SqlException
            Throw ex
        Finally
            connection.Close()
        End Try
        Return playersList
    End Function
End Class

Open in new window


FINALLY Players Class

Public Class Players
    Private m_PlayerID As Integer
    Private m_Firstname As String
    Private m_Lastname As String
    Private m_Position As String
    Private m_Height As String
    Private m_Weight As String

    Public Sub New()

    End Sub

    Public Property PlayerID() As Integer
        Get
            Return m_PlayerID
        End Get
        Set(ByVal value As Integer)
            m_PlayerID = value
        End Set
    End Property

    Public Property Firstname() As String
        Get
            Return m_Firstname
        End Get
        Set(ByVal value As String)
            m_Firstname = value
        End Set
    End Property

    Public Property Lastname() As String
        Get
            Return m_Lastname
        End Get
        Set(ByVal value As String)
            m_Lastname = value
        End Set
    End Property

    Public Property Position() As String
        Get
            Return m_Position
        End Get
        Set(ByVal value As String)
            m_Position = value
        End Set
    End Property

    Public Property Height() As String
        Get
            Return m_Height
        End Get
        Set(ByVal value As String)
            m_Height = value
        End Set
    End Property

    Public Property Weight() As String
        Get
            Return m_Weight
        End Get
        Set(ByVal value As String)
            m_Weight = value
        End Set
    End Property
End Class

Open in new window


Any suggestions pleas let me know or fixes thanks EE Never really had a problem doing this before but that was a few years ago. help EE Please
powerztomAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jens FiedererTest Developer/ValidatorCommented:
It looks like you commented out the code to add items to lvPlayers, and only left in code to add subitems to the item you didn't add?
0
Jacques Bourgeois (James Burger)PresidentCommented:
Please, specify which line causes a problem when you ask a question. This makes our job a lot of helping you a lot easier.

I suspect that it is line 33 of the second piece of code. The line that adds a new item to the ListView is commented out, so there is no item defined when you try to add subitems.
0
powerztomAuthor Commented:
When you add a new project to your current Project in my case I add a Class Library. Now whatever I name that Class Library I want to reference that new project in current Project Like for example I create a form then I add new project called NFLRoster which is a class library then within I create my Classes for the solution now in the first project that has a Form I add IMPORTS NFLRoster in beginning however I get that error line under the IMPORTS NFLRoster well the NFLRoster word. Now this stops me from using Classes I created in The class library called NFLRoster. Is there a step I missed out on. I think this is my problem. Please help EE
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Jacques Bourgeois (James Burger)PresidentCommented:
Have you tried removing the comment on line 33 as suggested?
0
powerztomAuthor Commented:
James AI remmed that line out cause it had a error line after it so I unremmed it and error line came back
this is the line lvPlayers.Items.Add(players.playersNumber) But any suggestions or do you understand what I am asking in my lastest post?
0
powerztomAuthor Commented:
I just chaged lvPlayers.Items.Add(players.playersNumber) to lvPlayers.Items.Add(players.Index) and got the data I needed except I got a few records with PlayerID AND NOTHING MORE for Firstname , Lastname ect. James do you know of a way to avoid showing these records. A Null detector ?

Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click
        Dim playersList As List(Of Players)
        Try
            playersList = PlayersSQL.GetPlayers
            If playersList.Count > 0 Then
                Dim players As Players
                For i As Integer = 0 To playersList.Count - 1
                    players = playersList(i)
                    lvPlayers.Items.Add(players.Index)
                    lvPlayers.Items(i).SubItems.Add(
                        CInt(players.PlayerID).ToString)
                    lvPlayers.Items(i).SubItems.Add(
                        CStr(players.Firstname))
                    lvPlayers.Items(i).SubItems.Add(
                        CStr(players.Lastname))
                    lvPlayers.Items(i).SubItems.Add(
                        CStr(players.Position))
                    lvPlayers.Items(i).SubItems.Add(
                        CStr(players.Height))
                    lvPlayers.Items(i).SubItems.Add(
                        CStr(players.Weight))
                Next
            Else
                MessageBox.Show("All playerss are paid in full.",
                    "No Balance Due")
                Me.Close()
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, ex.GetType.ToString)
            Me.Close()
        End Try
    End Sub

Open in new window

0
Jacques Bourgeois (James Burger)PresidentCommented:
Well, the ideal would be to filter them at the source, when you query your SQL database. But if for some reason you cannot do that, here is how you can do it in your code:

                    players = playersList(i)
If Cstr(players.FirstName).Length>0 AndAlso Cstr(players.LastName).Length>0 Then
                    lvPlayers.Items.Add(players.Index)
                    lvPlayers.Items(i).SubItems.Add(
                        CInt(players.PlayerID).ToString)
                    lvPlayers.Items(i).SubItems.Add(
                        CStr(players.Firstname))
                    lvPlayers.Items(i).SubItems.Add(
                        CStr(players.Lastname))
                    lvPlayers.Items(i).SubItems.Add(
                        CStr(players.Position))
                    lvPlayers.Items(i).SubItems.Add(
                        CStr(players.Height))
                    lvPlayers.Items(i).SubItems.Add(
                        CStr(players.Weight))
End If

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
powerztomAuthor Commented:
Thanks Bro
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.