Question

I want to pass List < int > ScoresList through -----------------------------------V

    private void lstStudents_SelectedIndexChanged(object sender, EventArgs e)
    {
        int target = lstStudents.SelectedIndex;
        if (target != -1)
        {
            Student student = (Student)students[target];
            txtScoreCount.Text = Convert.ToString(ScoresList.Count);
        }
    }

To access------------------------------------------------------------------------------^ the # of scores in my list.

When I do, I have access to my ScoresList, however, I get a "

No overload for 'lstStudents_SelectedIndexChanged' matches delegate 'System.EventHandler'.

The error is more specifically located here in my Designer.

this.lstStudents.SelectedIndexChanged += new System.EventHandler(this.lstStudents_SelectedIndexChanged);

I do not know what to put here that will resolve the issue. Since I'm here I assume I shouldn't pass a parameter through my event? How do I resolve this?

Was it helpful?

Solution

Adding parameter to event handler doesn't makes sense. Think of who responsible of passing the parameter value? The event handler get invoked by system upon occurrence of respective event. Also event handler method required to follow specific predefined signature, and adding parameter changes method signature, hence you got that error message.

Possible solution is to declare ScoresList as global variable so it will be accessible accross methods in the same scope, including your event handler method.

private List<int> ScoresList = new List<int>();

private void lstStudents_SelectedIndexChanged(object sender, EventArgs e)
{
    int target = lstStudents.SelectedIndex;
    if (target != -1)
    {
        Student student = (Student)students[target];
        txtScoreCount.Text = Convert.ToString(ScoresList.Count);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top