title: Assign a Collection class to the items of a list box
body: <p>I'm sure there should be an easier way to do this. I have a class based on Collection, and that class is a collection of another class. Currently, whenever I have a new item in my class, I assign that item to the listbox. I can't seem to figure out a way to assign all of the values in the collection class, because it is a collection, to the collection of the listbox. Any ideas? Thanks</p>
  
  <p>Ok, what I've done so far is I have a tostring override in the Class used in the collection. This is what I want the listbox to show.</p>
  
  <pre><code>      public override string ToString()
      {
  
          return string.Format("{0} {1}: {2}", tTypev.ToString(),
                  Datev.ToString("MM/dd/yyyy"), Amountv.ToString("C"));
      }
  </code></pre>
  
  <p>Which is what I want each item in the listbox to show. </p>
  
  <pre><code>                class Transactions : System.Collections.CollectionBase
                  {
                       ...
                  }
  </code></pre>
  
  <p>Is my collections class, containing a collection of the other class, Tansaction. Curently, I use the lstTransactions.Items.Add(), .Remove, .RemovAt, etc to add items to the list box, and the .Add(), .Remove, etc to add items to the Collection Class, Transactions. But I'm trying to decrease reliance on outside controls, and only use them in a few lines of code. I was trying to use something like:</p>
  
  <pre><code>lstTransactions.DataSource = (Transaction)myTrans;
  </code></pre>
  
  <p>but that didn't seem to work. Mainly because I couldn't figure out what property DataSource took.</p>
  
  <p>I also tried:</p>
  
  <pre><code>lstTransactions.Items = 
  </code></pre>
  
  <p>but it told me that items was read only.</p>