title: C# Selfmade ListView Item Collection
body: <p>I am making my own <code>ListView</code>. The <code>ListView</code> (a <code>UserControl</code>) currently uses a <code>BindingList</code> of <code>ListViewItems</code> and displays each item.</p>
  
  <p>I am doing an attempt to make my own <code>ListView</code> able to bind any Model-Object I want. This is why I made the <code>ListViewItem</code> inherit from the <code>Object</code> class. But now I am struggling to make a Collection/List that actually contains <code>ListViewItem</code> but where you can Add any <code>Object</code> you want.</p>
  
  <p>In short: How do I make a <code>List</code> or <code>Collection</code> that behaves like the <code>ListBox</code> or <code>ListView</code> Item Collection?</p>
  
  <p><strong>An Example:</strong></p>
  
  <pre><code>MyListView myListView = new MyListView();
  
  // Add an Object of type MyObject
  myListView.Items.Add(myObject);
  
  // Get the object back. (It is returned as a ListViewItem).
  ListViewItem sameObjectAsItem = myListView.Items[0];
  // Now I should be able to convert the ListViewItem back to MyObject via cast.
  MyObject sameObjectAgain = sameObjectAsItem as MyObject;
  </code></pre>
  
  <p><strong>What I have done so far:</strong></p>
  
  <p>I have created a class inheriting from <code>List&lt;Object&gt;</code>. But I can't cast <code>MyObject</code> to <code>ListViewItem</code>. Of course I could do a custom Cast converter, but I think I would have to create a new <code>ListViewItem</code> object and therefore would loose the reference.</p>
  
  <p><strong>Why am I doing this:</strong></p>
  
  <p>I am doing this on a Compact Framework .NET 3.5 project. CompactFramework only provides a basic <code>ListView</code> and I am creating a more advanced one. It works perfectly if I would use just <code>ListViewItems</code> but I want it to behave like the normal .NET ListView.</p>
  
  <p>Thanks in advance, I hope you can help me. Please ask if you need more information.</p>