Custom Controls that use Generics

J

Jared

I have created a custom control that uses a generic class to determine what
type of objects will be managed in the control.

The declaration is:
class MyCustomControl<T>:Combobox{
// class stuff
}

The control works great, but I can not use it in the designer. I was
wondering if anyone has had a similar problem and knows if there is a
solution.

Thanks.

Jared
 
B

Bob Powell [MVP]

This is a known issue.
Effectively you can't use an instance of a thing until it can be
instantiated and it can't be instantiated until you pass it the template
parameter...

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
J

Jared

Thanks. That leads to a second question. I have a similar problem if I
derive a class from the generic class that defines the type.

Using the original example:

class mysecondclass:myclass<someclass>{
}

Gives me an error stating that it cannot create myclass, even though the
template was passed.

I'm guessing it is related to the original issue, but I'm just curious why?

thanks.
 
O

Oliver Sturm

Hello Jared,
class mysecondclass:myclass<someclass>{
}

Gives me an error stating that it cannot create myclass, even though the
template was passed.

Are you sure? When I have this:

public class MyGenericPanel<T>: Panel {
public MyGenericPanel( ) {
}
}

public class MySpecificPanel: MyGenericPanel<string> {
public MySpecificPanel( ) {
}
}

I can drop a MySpecificPanel instance on a form in VS designer without a
problem.


Oliver Sturm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top