views:

692

answers:

1

I have a program that I want each person to have their own tab, each tab would be identical, however I would like to remove a tab if I need to.

private void addPerson(string name)
{
  TabPage tmp = new TabPage();
  ListView tmpList = new ListView();
  Button tmpButton = new Button();
  this.SuspendLayout();
  this.tabFrame.SuspendLayout();
  tmp.SuspendLayout();
  tmpList.SuspendLayout();
  tmpButton.SuspendLayout();
  ...
  //build the controll itself
  tmp.Controls.Add(tmpButton);
  tmp.Controls.Add(tmpList);
  tmp.Location = new System.Drawing.Point(4, 22);
  tmp.Name = name.Replace(' ', '_');
  tmp.Padding = new System.Windows.Forms.Padding(3);
  tmp.Size = new System.Drawing.Size(284, 240);
  tmp.TabIndex = 3;
  tmp.Text = name;
  tmp.UseVisualStyleBackColor = true;
  //add it to frame
  this.tabFrame.Controls.Add(tmp);
  tmpButton.ResumeLayout(true);
  tmpList.ResumeLayout(true);
  tmp.ResumeLayout(true);
  this.tabFrame.ResumeLayout(true);
  this.ResumeLayout(true);
{

Name will be in the form "Scott Chamberlain" so I remove the spaces and use underscores for the name field. I can add tabs fine, they show up correctly formated, however when I try to remove the tab using the code:

private void removePerson(string name)
{
  this.SuspendLayout();
  this.tabFrame.SuspendLayout();
  this.tabFrame.Controls.RemoveByKey(name.Replace(' ', '_'));
  this.tabFrame.ResumeLayout(true);
  this.ResumeLayout(true);
}

The tab does not disappear from my program. What am I missing to remove a tab?

+4  A: 
Samuel
Yes, it turns out i was passing a blank field in to name, I was not getting the text from a comboBox correctly.
Scott Chamberlain