title: How can I set up multiple combo-boxes with the same data source?
body: <p>I'm trying to create a set-up interface for a program which simulates a board game in C#. I have 1 ComboBox which allows the user to select the number of players, which in turn hides or displays the selected number of comboboxes. Each combobox should initially have all four options (Red, Blue, Green, Yellow), however when a color is selected from one combobox, it should remove that option from the remaining comboboxes (i.e. if player1 selects Red, then players 2-4 should not also be able to select red). Right now I am trying to use multiple Lists to display the information in each combobox, but the code I have written to remove the colors from the remaining comboboxes has yielded a number of unintended consequences. I'm wondering if there is a better way in which to share the data between all of the comboboxes. Any help/ideas would be greatly appreciated!</p>
  
  <p>I have attached my code below to give you a better idea of what I'm working with. Thank you for your time!</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  
  namespace StartPage.CS
  {
      public partial class SetUp : Form
      {
          // Create a static array to hold the players
          public static Player[] players { get; private set; }
  
          // create lists to hold the colors for each player
          List&lt;String&gt; player1Colors = new List&lt;String&gt;();
          List&lt;String&gt; player2Colors = new List&lt;String&gt;();
          List&lt;String&gt; player3Colors = new List&lt;String&gt;();
          List&lt;String&gt; player4Colors = new List&lt;String&gt;();
  
  
          public SetUp()
          {
              InitializeComponent();
          }
  
          private void SetUp_Load(object sender, EventArgs e)
          {
              // initialize the selected index to 2 players
              cboSelectPlayers.SelectedIndex = 0;
  
              // add the colors to each list
              player1Colors.Add("Red");
              player1Colors.Add("Blue");
              player1Colors.Add("Green");
              player1Colors.Add("Yellow");
  
              player2Colors.Add("Red");
              player2Colors.Add("Blue");
              player2Colors.Add("Green");
              player2Colors.Add("Yellow");
  
              player3Colors.Add("Red");
              player3Colors.Add("Blue");
              player3Colors.Add("Green");
              player3Colors.Add("Yellow");
  
              player4Colors.Add("Red");
              player4Colors.Add("Blue");
              player4Colors.Add("Green");
              player4Colors.Add("Yellow");
  
              // add each list to it's respective comboBox
              for (int i = 0; i &lt; player1Colors.Count; ++i)
              {
                  cboPlayer1Color.Items.Add(player1Colors[i]);
              }
              for (int i = 0; i &lt; player2Colors.Count; ++i)
              {
                  cboPlayer2Color.Items.Add(player2Colors[i]);
              }
              for (int i = 0; i &lt; player3Colors.Count; ++i)
              {
                  cboPlayer3Color.Items.Add(player3Colors[i]);
              }
              for (int i = 0; i &lt; player4Colors.Count; ++i)
              {
                  cboPlayer4Color.Items.Add(player4Colors[i]);
              }
          }
  
          // method to create the players and add them to the array
  
  
          // handles displaying the number of players to select colors
          private void cboSelectPlayers_SelectedIndexChanged(object sender, EventArgs e)
          {
              if (cboSelectPlayers.SelectedIndex == 0) // if players = 2
              {
                  lblPlayer3Select.Hide();
                  cboPlayer3Color.Hide();
                  lblPlayer4Select.Hide();
                  cboPlayer4Color.Hide();
              }
              else if (cboSelectPlayers.SelectedIndex == 1) // if players = 3
              {
                  lblPlayer3Select.Show();
                  cboPlayer3Color.Show();
                  lblPlayer4Select.Hide();
                  cboPlayer4Color.Hide();
              }
              else if (cboSelectPlayers.SelectedIndex == 2) // if players  4
              {
                  lblPlayer3Select.Show();
                  cboPlayer3Color.Show();
                  lblPlayer4Select.Show();
                  cboPlayer4Color.Show();
              }
          }
  
          // handles removing player1's selected color from other comboboxes
          private void cboPlayer1Color_SelectedIndexChanged(object sender, EventArgs e)
          {
              if (cboPlayer1Color.SelectedItem == "Red")
              {
                  // remove red from the other comboboxes
                  player2Colors.Remove("Red");
                  player3Colors.Remove("Red");
                  player4Colors.Remove("Red");
  
                  // make sure that the other colors that are supposed to be there are
                  if (!player2Colors.Contains("Blue") &amp;&amp; !player3Colors.Contains("Blue") &amp;&amp; !player4Colors.Contains("Blue"))
                  {
                      player2Colors.Add("Blue");
                      player3Colors.Add("Blue");
                      player4Colors.Add("Blue");
                  }
                  if (!player2Colors.Contains("Yellow") &amp;&amp; !player3Colors.Contains("Yellow") &amp;&amp; !player4Colors.Contains("Yellow"))
                  {
                      player2Colors.Add("Yellow");
                      player3Colors.Add("Yellow");
                      player4Colors.Add("Yellow");
                  }
                  if (!player2Colors.Contains("Green") &amp;&amp; !player3Colors.Contains("Green") &amp;&amp; !player4Colors.Contains("Green"))
                  {
                      player2Colors.Add("Green");
                      player3Colors.Add("Green");
                      player4Colors.Add("Green");
                  }
              }
              else if (cboPlayer1Color.SelectedItem == "Blue")
              {
                  // remove blue from the other comboboxes
                  player2Colors.Remove("Blue");
                  player3Colors.Remove("Blue");
                  player4Colors.Remove("Blue");
  
                  // make sure that the other colors that are supposed to be there are
                  if (!player2Colors.Contains("Red") &amp;&amp; !player3Colors.Contains("Red") &amp;&amp; !player4Colors.Contains("Red"))
                  {
                      player2Colors.Add("Red");
                      player3Colors.Add("Red");
                      player4Colors.Add("Red");
                  }
                  if (!player2Colors.Contains("Yellow") &amp;&amp; !player3Colors.Contains("Yellow") &amp;&amp; !player4Colors.Contains("Yellow"))
                  {
                      player2Colors.Add("Yellow");
                      player3Colors.Add("Yellow");
                      player4Colors.Add("Yellow");
                  }
                  if (!player2Colors.Contains("Green") &amp;&amp; !player3Colors.Contains("Green") &amp;&amp; !player4Colors.Contains("Green"))
                  {
                      player2Colors.Add("Green");
                      player3Colors.Add("Green");
                      player4Colors.Add("Green");
                  }
              }
              else if (cboPlayer1Color.SelectedItem == "Yellow")
              {
                  // remove yellow from the other comboboxes
                  player2Colors.Remove("Yellow");
                  player3Colors.Remove("Yellow");
                  player4Colors.Remove("Yellow");
  
                  // make sure that the other colors that are supposed to be there are
                  if (!player2Colors.Contains("Red") &amp;&amp; !player3Colors.Contains("Red") &amp;&amp; !player4Colors.Contains("Red"))
                  {
                      player2Colors.Add("Red");
                      player3Colors.Add("Red");
                      player4Colors.Add("Red");
                  }
                  if (!player2Colors.Contains("Blue") &amp;&amp; !player3Colors.Contains("Blue") &amp;&amp; !player4Colors.Contains("Blue"))
                  {
                      player2Colors.Add("Blue");
                      player3Colors.Add("Blue");
                      player4Colors.Add("Blue");
                  }
                  if (!player2Colors.Contains("Green") &amp;&amp; !player3Colors.Contains("Green") &amp;&amp; !player4Colors.Contains("Green"))
                  {
                      player2Colors.Add("Green");
                      player3Colors.Add("Green");
                      player4Colors.Add("Green");
                  }
              }
              else if (cboPlayer1Color.SelectedItem == "Green")
              {
                  // remove green from the other comboboxes
                  player2Colors.Remove("Green");
                  player3Colors.Remove("Green");
                  player4Colors.Remove("Green");
  
                  // make sure that the other colors that are supposed to be there are
                  if (!player2Colors.Contains("Red") &amp;&amp; !player3Colors.Contains("Red") &amp;&amp; !player4Colors.Contains("Red"))
                  {
                      player2Colors.Add("Red");
                      player3Colors.Add("Red");
                      player4Colors.Add("Red");
                  }
                  if (!player2Colors.Contains("Blue") &amp;&amp; !player3Colors.Contains("Blue") &amp;&amp; !player4Colors.Contains("Blue"))
                  {
                      player2Colors.Add("Blue");
                      player3Colors.Add("Blue");
                      player4Colors.Add("Blue");
                  }
                  if (!player2Colors.Contains("Yellow") &amp;&amp; !player3Colors.Contains("Yellow") &amp;&amp; !player4Colors.Contains("Yellow"))
                  {
                      player2Colors.Add("Yellow");
                      player3Colors.Add("Yellow");
                      player4Colors.Add("Yellow");
                  }
              }
              // clear and then update the other comboboxes
              cboPlayer2Color.Items.Clear();
              cboPlayer3Color.Items.Clear();
              cboPlayer4Color.Items.Clear();
              for (int i = 0; i &lt; player2Colors.Count; ++i)
              {
                  cboPlayer2Color.Items.Add(player2Colors[i]);
              }
              for (int i = 0; i &lt; player3Colors.Count; ++i)
              {
                  cboPlayer3Color.Items.Add(player3Colors[i]);
              }
              for (int i = 0; i &lt; player4Colors.Count; ++i)
              {
                  cboPlayer4Color.Items.Add(player4Colors[i]);
              }
          }
  
          // handles removing player2's selected color from other comboboxes
          private void cboPlayer2Color_SelectedIndexChanged(object sender, EventArgs e)
          {
              if (cboPlayer2Color.SelectedItem == "Red")
              {
                  // remove red from the other comboboxes
                  player1Colors.Remove("Red");
                  player3Colors.Remove("Red");
                  player4Colors.Remove("Red");
  
                  // make sure that the other colors that are supposed to be there are
                  if (!player1Colors.Contains("Blue") &amp;&amp; !player3Colors.Contains("Blue") &amp;&amp; !player4Colors.Contains("Blue"))
                  {
                      player1Colors.Add("Blue");
                      player3Colors.Add("Blue");
                      player4Colors.Add("Blue");
                  }
                  if (!player1Colors.Contains("Yellow") &amp;&amp; !player3Colors.Contains("Yellow") &amp;&amp; !player4Colors.Contains("Yellow"))
                  {
                      player1Colors.Add("Yellow");
                      player3Colors.Add("Yellow");
                      player4Colors.Add("Yellow");
                  }
                  if (!player1Colors.Contains("Green") &amp;&amp; !player3Colors.Contains("Green") &amp;&amp; !player4Colors.Contains("Green"))
                  {
                      player1Colors.Add("Green");
                      player3Colors.Add("Green");
                      player4Colors.Add("Green");
                  }
              }
              else if (cboPlayer2Color.SelectedItem == "Blue")
              {
                  // remove blue from the other comboboxes
                  player1Colors.Remove("Blue");
                  player3Colors.Remove("Blue");
                  player4Colors.Remove("Blue");
  
                  // make sure that the other colors that are supposed to be there are
                  if (!player1Colors.Contains("Red") &amp;&amp; !player3Colors.Contains("Red") &amp;&amp; !player4Colors.Contains("Red"))
                  {
                      player1Colors.Add("Red");
                      player3Colors.Add("Red");
                      player4Colors.Add("Red");
                  }
                  if (!player1Colors.Contains("Yellow") &amp;&amp; !player3Colors.Contains("Yellow") &amp;&amp; !player4Colors.Contains("Yellow"))
                  {
                      player1Colors.Add("Yellow");
                      player3Colors.Add("Yellow");
                      player4Colors.Add("Yellow");
                  }
                  if (!player1Colors.Contains("Green") &amp;&amp; !player3Colors.Contains("Green") &amp;&amp; !player4Colors.Contains("Green"))
                  {
                      player1Colors.Add("Green");
                      player3Colors.Add("Green");
                      player4Colors.Add("Green");
                  }
              }
              else if (cboPlayer2Color.SelectedItem == "Yellow")
              {
                  // remove yellow from the other comboboxes
                  player1Colors.Remove("Yellow");
                  player3Colors.Remove("Yellow");
                  player4Colors.Remove("Yellow");
  
                  // make sure that the other colors that are supposed to be there are
                  if (!player1Colors.Contains("Red") &amp;&amp; !player3Colors.Contains("Red") &amp;&amp; !player4Colors.Contains("Red"))
                  {
                      player1Colors.Add("Red");
                      player3Colors.Add("Red");
                      player4Colors.Add("Red");
                  }
                  if (!player1Colors.Contains("Blue") &amp;&amp; !player3Colors.Contains("Blue") &amp;&amp; !player4Colors.Contains("Blue"))
                  {
                      player1Colors.Add("Blue");
                      player3Colors.Add("Blue");
                      player4Colors.Add("Blue");
                  }
                  if (!player1Colors.Contains("Green") &amp;&amp; !player3Colors.Contains("Green") &amp;&amp; !player4Colors.Contains("Green"))
                  {
                      player1Colors.Add("Green");
                      player3Colors.Add("Green");
                      player4Colors.Add("Green");
                  }
              }
              else if (cboPlayer2Color.SelectedItem == "Green")
              {
                  // remove green from the other comboboxes
                  player1Colors.Remove("Green");
                  player3Colors.Remove("Green");
                  player4Colors.Remove("Green");
  
                  // make sure that the other colors that are supposed to be there are
                  if (!player1Colors.Contains("Red") &amp;&amp; !player3Colors.Contains("Red") &amp;&amp; !player4Colors.Contains("Red"))
                  {
                      player1Colors.Add("Red");
                      player3Colors.Add("Red");
                      player4Colors.Add("Red");
                  }
                  if (!player1Colors.Contains("Blue") &amp;&amp; !player3Colors.Contains("Blue") &amp;&amp; !player4Colors.Contains("Blue"))
                  {
                      player1Colors.Add("Blue");
                      player3Colors.Add("Blue");
                      player4Colors.Add("Blue");
                  }
                  if (!player1Colors.Contains("Yellow") &amp;&amp; !player3Colors.Contains("Yellow") &amp;&amp; !player4Colors.Contains("Yellow"))
                  {
                      player1Colors.Add("Yellow");
                      player3Colors.Add("Yellow");
                      player4Colors.Add("Yellow");
                  }
              }
              // clear and then update the other comboboxes
              cboPlayer1Color.Items.Clear();
              cboPlayer3Color.Items.Clear();
              cboPlayer4Color.Items.Clear();
              for (int i = 0; i &lt; player2Colors.Count; ++i)
              {
                  cboPlayer2Color.Items.Add(player2Colors[i]);
              }
              for (int i = 0; i &lt; player3Colors.Count; ++i)
              {
                  cboPlayer3Color.Items.Add(player3Colors[i]);
              }
              for (int i = 0; i &lt; player4Colors.Count; ++i)
              {
                  cboPlayer4Color.Items.Add(player4Colors[i]);
              }
          }
  
          // handles removing player3's selected color from other comboboxes
          private void cboPlayer3Color_SelectedIndexChanged(object sender, EventArgs e)
          {
  
          }
  
          // handles removing player4's selected color from other comboboxes
          private void cboPlayer4Color_SelectedIndexChanged(object sender, EventArgs e)
          {
  
          }
  
          /* method to update the comboBoxes
          private void updateComboBoxes()
          {
              for (int i = 0; i &lt; player1Colors.Count; ++i)
              {
                  cboPlayer1Color.Items.Add(player1Colors[i]);
              }
              for (int i = 0; i &lt; player2Colors.Count; ++i)
              {
                  cboPlayer2Color.Items.Add(player2Colors[i]);
              }
              for (int i = 0; i &lt; player3Colors.Count; ++i)
              {
                  cboPlayer3Color.Items.Add(player3Colors[i]);
              }
              for (int i = 0; i &lt; player4Colors.Count; ++i)
              {
                  cboPlayer4Color.Items.Add(player4Colors[i]);
              }
          }*/
  
          private void btnStart_Click(object sender, EventArgs e)
          {
              //Control control = new Control(players); 
              GameBoard gameboard = new GameBoard();
              gameboard.ShowDialog();
              this.Close();
          }
      }
  }
  </code></pre>