Quote Originally Posted by Doc618 View Post
Okay after about 3 hours of poking around i found the problem out
Code:
private void FrmHighCard_Load(object sender, EventArgs e)
        {
            StreamReader reader;
            string player;
            try
            {
                reader = new StreamReader("Names.dat");
                player = reader.ReadLine();
                while (player != null)
                {
                    cboxPlayer1.Items.Add(player);
                    player = reader.ReadLine(); //*******MISSING THIS READLINE COMMAND******
                }

                reader.Close();

            }
            catch
            {
                MessageBox.Show("File Read Error");
            }
        }
Sorry for missing that I skimmed through the code and everything looked correct.

From my understanding you have now resolved your issue but you do not need string player as that is really not doing anything.

You could shorten your code and have the same functions with
Code:
// Create reader
StreamReader reader = new StreamReader("Names.dat");

// Loop until end of file is reached
while (reader.Peek() > -1)
{
      // Add player names to combo box
      cboxPlayer1.Items.Add(reader.ReadLine());
}

// Close reader
reader.Close();
What Mur16 was saying in his post is that according to your code every time you choose a new player in combo box 1 it opens up the Names.dat file again and reads of the names to add to cboxPlayer2. In a small program like this there is no real performance issue since data is miniscule. You mentioned it was a class assignment so from my guess is that the instructor is drilling the code into you guys by making you repeatedly type the same code over and over but in reality all the data for your application can be loaded at the start of the application.

Since both combo boxes effectively have the same names and none of them change you could simply add the names to both combo boxes in one go like this.
Code:
// Create reader
StreamReader reader = new StreamReader("Names.dat");
string playerName = "";

// Loop until end of file is reached
while (reader.Peek() > -1)
{
      // Read line and save it to string so it can be added to players combo box
      playerName = reader.ReadLine();

      // Add player names to combo box
      cboxPlayer1.Items.Add(playerName);
      cboxPlayer2.Items.Add(playerName);
}

// Close reader
reader.Close();
This way it adds the names to both combo boxes and you don't have to keep opening the file as you are now with

Code:
        private void cboxPlayer1_SelectedIndexChanged(object sender, EventArgs e)
        {
            StreamReader reader;
            string player;
            cboxPlayer2.Items.Clear();

            try
            {
                reader = new StreamReader("players.dat");
                player = reader.ReadLine();
                while (player != null)
                {
                    if (cboxPlayer1.SelectedItem.ToString() != player)
                        cboxPlayer2.Items.Add(player);
                    player = reader.ReadLine();
                }

                reader.Close();

            }
            catch
            {
                MessageBox.Show("File Read Error");
            }
        }
    }