Q:

Combobox with strong typed items

I want to create a control that inherits from ComboBox. I want a combobox which only accepts items of a certain type.
So I need to overrule the Items property. (Notice the new keyword).
But what do I put in the set region of this overruled Items property?
    new public List<TimeSpanItemClass> Items
    {
        get
        {
            return base.Items.Cast<TimeSpanItemClass>().ToList();
        }
        set
        {
            ?
        }
    }

I can't figure it out, and searching on Google yields close to nothing.

A:

The combobox already supports this.
Put your list of elements into the property DataSource:
var persons = new List<Person>();
// ToDo: fill list with some values...

myComboBox.DataSource = persons;

Enter into the property DisplayMember the property of the object that will represent what the user should see. If you don't set it, the combo box will call .ToString() on the selected element.
myComboBox.DisplayMember = "FullName";

Enter into the property ValueMember the property you like to receive from object in code. If you don't set it, the combo box will return the object itself.
myComboBox.ValueMember = "Born";

To get the currently selected object out of the combobox simply cast the property SelectedValue to the desired type.
private void OnComboBoxFormatSelectedIndexChanged(object sender, EventArgs e)
{
    DateTime born = (DateTime)comboBox.SelectedValue
}

Update for altering list after assignment
If you need to alter the list or one if its items after you have assigned the data source to the combo box you have to inform the combo box about this change. The most trivial way is to simply re-assign the data source to the combo box:
myComboBox.DataSource = persons;

A more cleaner way would be if the list itself could fire up an event if any change had happened. This feature is implemented by the BindingList<T> and let the combo box automatically be updated if you alter the list by adding or removing an element from it.
The next step of information flow would be to inform the combo box if an item itself has been changed (in our example e.g. the last name of a person). To accomplish this your objects within the list have either to implement a PropertyNameChanged event (in our example this would be LastNameChanged cause the property name would be LastName) or you have to implement the INotifyPropertyChanged within your class. If you did this and you use a binding list, these events will automatically be forwarded to the combo box and the value will be updated there too.
Caution: In the first step the usage of a BindingList and NotifyPropertyChanged works quite good, but you can really get into trouble if you are going to change the list or an object property out of another thread (leads to Cross-Thread-Exceptions). But it is also possible to avoid this.
You simply need another layer between your ComboBox and the BindingList; a BindingSource. This has the ability to suspend and resume the notification chain, so that you can alter the list from another thread:
var persons = new BindingList<Person>();
var bindingSource = new BindingSource();
bindingSource.DataSource = persons;
comboBox.DataSource = bindingSource;

// Suspend change the list from another thread,
// and resume on the gui thread.
bindingSource.SuspendBinding();
Task.Factory.StartNew(() => persons.Add(Person.GetRandomFromDatabase()))
            .ContinueWith(finishedTask => bindingSource.ResumeBinding(),
                            TaskScheduler.FromCurrentSynchronizationContext());

