views:

138

answers:

1

This is the exact same question as this one: “Could not find type” error loading a form in the Designer

Before anyone goes closing my question please read that one. You will realize that it did not get a real answer. I hope to get a full answer (rather than a workaround) from this question.

When I create a class that descends from Control and uses generics, that class fails to load in the designer.

Here is and example:

class OwnerDrawnListBox<T> : System.Windows.Forms.Control
{

    private readonly List<T> _items;

    // Other list box private stuff here

    public OwnerDrawnListBox()
    {
        _items = new List<T>();
    }

    // More List box code
}

I then use this in my designer:

private OwnerDrawnListBox<Bag> lstAvailable;

private void InitializeComponent()
{
    // Used to be System.Windows.Forms.ListBox();
    this.lstAvailable = new ARUP.ScanTrack.Mobile.OwnerDrawnListBox<Bag>(); 
    // Other items
}

If the generic class is subclassed (to a non-generic) then the referenced question says that it works fine (ie if I made Class BagOwnerDrawListBox: OwnerDrawnListBox<Bag>).

What I want to know is there a way to "fix" this so that the generic item is accepted by the designer?

Side Note: I am using the Compact Framework.

A: 

The Windows Forms designer doesn't support generic controls as far as I know. The only way to maintain designer support is to use a non-generic subclass, like you said. At any rate, any "fix" is simply going to be a workaround.

Will Vousden