TheHDTrip 0 Newbie Poster

I'm creating a program that maintains student scores. I've created a class called students that stores the data and displays it in a list box. Once the user clicks btnAdd a new form (frmAddStudent) loads that allows them to add the user by name and their scores and display it in the listbox in the main form. It also allows the update/delete functions. I can succesfully add students to the list and edit them, but when I press the ok button in the update students form I get the error, "System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index'". I know this means that the argument passed was out of range, but I'm not sure how. Any help is appreciated. Thanks! I've included my source code if you want a deeper look.

frmUpdateStudent.cs

     private void UpdateButton_Click_1(object sender, EventArgs e)  //open update form for current student
            {
                Student Form1 = new Student();
                Form1.Name = StudentName.Text;
                parentForm.UpdateStudent(index, Form1);
                Close();

        }


Form1.cs

     public Student GetStudent(int id)  //Get student index
            {
                return studentList[id];

        }

Student.cs

     public class Student
        {
            public List<int> Scores = new List<int>();

        public string Name
        { get; set; }

        public bool AddScore(int score)
        {
            try
            {
                Scores.Add(score);
            }
            catch { return false; }
            return true;
        }

        public List<int> GetScores()
        {
            return Scores;
        }

        public int GetScoreAt(int index)
        {
            return (int)Scores[index];
        }

        public int GetScoreTotal()
        {
            int sum = 0;
            foreach (int score in Scores)
            {
                sum += score;
            }
            return sum;
        }

        public int GetScoreCount()
        {
            return Scores.Count;
        }

        public int GetScoreAverage()
        {
            return GetScoreTotal() / GetScoreCount();
        }

        public void DestroyScores()
        {
            Scores = new List<int>();

    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.