QuestionsC# Application Lesson 22, @ 33min40sec
Peter Edenburg asked 7 months ago

Hello Tim,
I’ve read through the questions here and there are not many of them, so things are going very well for everyone. That’s good.
I ran into a problem however. When following along with lesson 22, at the 33:40 minute marker all should be going as planned when changing to round 2. For me that was not the case.
I figured it out, but I am curious why it went wrong for me, having typed the code along with you, and I believe verbatim (I watched the video over and over to make sure) and since
there are no questions from other users about this lesson, then came the moment of truth: having to do my own debugging.
The problem started here: The method ‘LoadMatchups(int round)’, within the if-block, clears the selectedMatchups binding list. Since this private variable retains what was added to it when loading the tournament, clearing it triggers the event ‘matchupListBox_SelectedIndexChanged’ from ‘A’ selected index to ‘No’ selected index. The event in turn calls LoadMatchup(MatchupModel m), but m is null in this scenario, thus throws an error on the line that has the ‘for’ loop declaration.
Now, I recently upgraded VS Prof from the 2013 to the 2017 version, but I don’t know if that’s why I had this glitch. It took me quite some time, but here is my solution.
I changed the following event like so:
private void matchupListBox_SelectedIndexChanged(object sender, EventArgs e)
if (selectedMatchups.Count > 0)
LoadMatchup((MatchupModel) matchupListBox.SelectItem);

1 Answers
Tim Corey answered 7 months ago

Thanks for identifying that and great job debugging it. Yep, there is a bug in the code at this point. I believe I fix it later on in the course but it is obviously better if you fix it right away. Nice work.

Your Answer