Composite Design Pattern
<p>I have a ListBox with elements and I need to display the elements, I have that working but I want to add an option to remove the selected item, here is the problem... I removed it but I was removing from the listbox not from the elements class, what can I do to remove the items from the tree? Here is my code:</p>

<p>Form 1:</p>

<pre><code>private void btnBuildPartsList_Click(object sender, EventArgs e)
{
    Assembly topWidget = new Assembly("Main Assembly", 1);
    Assembly chassis = new Assembly("Chassis", 1);
    Assembly display = new Assembly("Display", 1);
    Assembly powerSupply = new Assembly("Power Supply", 1);
    Part bolt = new Part("Bolt", 24);
    Part mainCase = new Part("Case", 1);
    Part screen = new Part("Screen", 3);
    Part displayElectronics = new Part("Display Electronics", 3);
    Part transformer = new Part("Transformer", 1);
    Part powerBoard = new Part("Power Board", 1);
    Part ductTape = new Part("Duct Tape", 5);
    Part gum = new Part("Bubble Gum", 25);

    topWidget.Add(chassis);
    topWidget.Add(display);
    topWidget.Add(powerSupply);
    chassis.Add(mainCase);
    chassis.Add(bolt);
    display.Add(screen);
    display.Add(displayElectronics);
    powerSupply.Add(transformer);
    powerSupply.Add(powerBoard);
    topWidget.Add(ductTape);
    topWidget.Add(gum);

    DisplayPartsList(topWidget);
}

private void DisplayPartsList(Assembly topWidget)
{
     List&lt;string&gt; partsList = new List&lt;string&gt;();
     topWidget.WritePartsList(partsList);

     listParts.Items.Clear();
     listParts.Items.AddRange(partsList.ToArray());
}
</code></pre>

<p>And here is my Assembly class:</p>

<pre><code>namespace Composite
{
    public class Assembly : BaseAssembly
    {
        private List&lt;BaseAssembly&gt; elements = new List&lt;BaseAssembly&gt;();

        public Assembly(string name, int quantity)
            : base(name, quantity)
        {
        }

        public override void Add(BaseAssembly assembly)
        {
            elements.Add(assembly);
        }

        public override void Remove(BaseAssembly assembly)
        {
            elements.Remove(assembly);
        }

        public override void WritePartsList(List&lt;string&gt; list)
        {
            list.Add(Quantity.ToString() + " - " + Name);

            foreach (BaseAssembly assembly in elements)
            {
                assembly.WritePartsList(list);
            }
        }
    }
}
</code></pre>

<p>I think that this code is enough, all the other code it's like in other Composite Desing pattern code, now, how can I do that remove item function? Selecting <code>x</code> element from my listbox. Like I said before I was removing the item from <code>the listbox</code> but I want to remove it from all the class. Thanks in advance. </p>