I think the problem is in the last cycle.
Do the following:
cartListBox.Items.Clear(); for (int i = 0; i < movieArray.Length; i++) { cartListBox.Items.Add(movieArray[i].ToString()); }
When you clear cartListBox.Items.Clear(); , it should not be taken as a loop counter, for example, for (int i = 0; i < cartListBox.Items.Count; i++)
cartListBox.Items.Count was creating a problem.
source share