O'Reilly Forums: Let's Build A House And Hide And Seek - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Let's Build A House And Hide And Seek SelectedIndex

#1 User is offline   BassNoteC# 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 03-January 13

Posted 03 January 2013 - 12:14 PM

Hello I am new to the book and this forum I am having a difficulty with this project and hoping that someone can help me.

I fully looked at the program I made from the book and compared it to the project file here in the website and I cannot seem to see any difference other than mine is not working.

Whenever I run my program it says
"ArgumentOutOfRangeException was unhandled" InvalidArgument=Value of '0' is not valid for 'SelectedIndex'.Parameter name: SelectedIndex

on the code below

private void RedrawForm()
{
exits.Items.Clear();
for (int i = 0; i > currentLocation.Exits.Length; i++)
exits.Items.Add(currentLocation.Exits[i].Name);
exits.SelectedIndex = 0;

I looked at the working file from the website and I see no difference to what I have done but I just cant' seem to make my project work. Do I have to change any properties to the combobox or event handlers? Any feedback on this would be great. Thank You
0

#2 User is offline   Sikta_26785 

  • Active Member
  • PipPipPip
  • Group: Members
  • Posts: 67
  • Joined: 18-May 11

Posted 04 January 2013 - 11:39 AM

View PostBassNoteC#, on 03 January 2013 - 12:14 PM, said:

for (int i = 0; i > currentLocation.Exits.Length; i++)


This is supposed to be:

for (int i = 0; i < currentLocation.Exits.Length; i++)


0 will never be greater than the number of exits thus you will never add the exits to the combobox. Trying to set the selectedindex of an empty combobox causes the exception.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users