title: Dynamic names for panels
body: <p>I'm working on a program that is supposed to use with multiple users. I'm getting the users from a database. So far so good...</p>
  
  <p>I'm dynamically adding a panel to the form, which would hold some data. I'm using this piece of code to achieve that:</p>
  
  <pre><code>string panel_name = "email_in_" + user_credentials[counter_snel][0];
  Panel new_user_panel = new Panel();
  new_user_panel.AutoSize = true;
  new_user_panel.Dock = System.Windows.Forms.DockStyle.Fill;
  new_user_panel.Location = new System.Drawing.Point(0, 0);
  new_user_panel.Name = panel_name;
  new_user_panel.Visible = false;
  
  Label new_item = new Label();
  new_item.AutoSize = true;
  new_item.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  string new_item_text = string.Format("{0,0}\n{1,0}\n{2,0}", user_credentials[counter_snel][1], user_credentials[counter_snel][2],user_credentials[counter_snel][9]);
  new_item.Text = new_item_text;
  splitContainer2.panel_name.Controls.Add(new_item);
  </code></pre>
  
  <p>as you will probably notice, this line of code is not working:</p>
  
  <pre><code>splitContainer2.panel_name.Controls.Add(new_item);
  </code></pre>
  
  <p>How can I achieve this, so when I want to make panel email_in_1 visible, I can use that, and make email_in_8 not visible?</p>
  
  <h3>### EDIT 1 ###</h3>
  
  <p>the code now looks like this:</p>
  
  <pre><code>string panel_name = "email_in_" + user_credentials[counter_snel][0];
  Panel new_user_panel = new Panel();
  new_user_panel.AutoSize = true;
  new_user_panel.Dock = System.Windows.Forms.DockStyle.Fill;
  new_user_panel.Location = new System.Drawing.Point(0, 0);
  new_user_panel.Name = panel_name;
  new_user_panel.Visible = true;
  user_email_in_panels.Add(new_user_panel);
  splitContainer2.Panel1.Controls.Add(new_user_panel);
  
  Label new_item = new Label();
  new_item.AutoSize = true;
  new_item.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  string new_item_text = string.Format("{0,0}\n{1,0}\n{2,0}", user_credentials[counter_snel][1], user_credentials[counter_snel][2],user_credentials[counter_snel][9]);
  new_item.Text = new_item_text;
  int aantal_panels = 0;
  foreach (Panel panel in user_email_in_panels) {
          aantal_panels++;
  }
  int counter_1 = 0;
  foreach (Panel panel in user_email_in_panels) {
          if(counter_1 == (aantal_panels -1)){
                 MessageBox.Show("We are here");
                 panel.Controls.Add(new_item);
                 splitContainer1.Panel1.Controls.Add(panel);
          }
          counter_1++;
  }
  </code></pre>
  
  <p>But somehow, i don't see any labels shown in the form... am i missing something? The messsagebox with the text We are Here is shown, so it come's to the add statement....</p>
  
  <p>and i've got an another question besides my first question. My question is, how can i make the counter of the list better? </p>
  
  <h3>### Edit for Sean Vaughn</h3>
  
  <p>i've updated it to this:</p>
  
  <pre><code>public class MyPanelClass {
      public string Name {
          get;
          set;
      }
  
      public bool Visible {
          get;
          set;
      }
  
      public string YourLabelsText {
          get;
          set;
      }
  }
  
  Label new_item = new Label();
  new_item.AutoSize = true;
  new_item.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  string new_item_text = string.Format("{0,0}\n{1,0}\n{2,0}", user_credentials[counter_snel][1], user_credentials[counter_snel][2], user_credentials[counter_snel][9]);
  new_item.Text = new_item_text;
  
  Panel base_panel = new Panel();    //this is your base panel, you don't need to add this line of code because Visual Studio will do that for you.
  List&lt;MyPanelClass&gt; myPanelList = new List&lt;MyPanelClass&gt;();    //this will keep records of all of your panels.
  
  MyPanelClass panel_name = new MyPanelClass();
  panel_name.Name = "email_in_" + user_credentials[counter_snel][0]; ;
  panel_name.Visible = true;
  panel_name.YourLabelsText = string.Format("{0,0}\n{1,0}\n{2,0}", user_credentials[counter_snel][1], user_credentials[counter_snel][2], user_credentials[counter_snel][9]);
  
  //Now add the new created panel to the list.
  myPanelList.Add(panel_name);
  
  base_panel.Name = myPanelList[counter_snel].Name;
  base_panel.Visible = myPanelList[counter_snel].Visible; //You probably don't need this because base_panel will always be visible
  new_item.Text = myPanelList[counter_snel].YourLabelsText;
  </code></pre>
  
  <p>But i still doesn't see anything...
  Does it matter that it execudes in an public void??? i don't think so, but it want to elliminate all the possibilities...</p>