Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / June 2007

Tip: Looking for answers? Try searching our database.

inherit form and generics

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
CassioT - 26 Jun 2007 20:57 GMT
Hi. I want to create a base form class with a generic parameter.

public BaseForm<T> : Form
{}

public MyForm : BaseForm<MyType>
{}

The problem here is that the inherited form doesn't work in the visual
studio designer but the execution is perfect. Without the generic
parameter it works in the designer.

Is there a way to this or, does anyone has a better solution?

Thank you

Cassio Tavares
Smokey Grindle - 26 Jun 2007 21:39 GMT
the designer has to be able to instanciate the form itself for it to work in
the designer... if it cant do this, the form wont load

> Hi. I want to create a base form class with a generic parameter.
>
[quoted text clipped - 13 lines]
>
> Cassio Tavares
CassioT - 26 Jun 2007 22:12 GMT
So, I think the designer doesn't know what to pass in the generic
parameter.

I have a temporary solution but I don't like it. When I have to use
the designer,
I change the inheritance to System.Windows.Forms.Form. Is not a good
solution
because I can't add a grid to the base form and design it in the
inherited.

> the designer has to be able to instanciate the form itself for it to work in
> the designer... if it cant do this, the form wont load
[quoted text clipped - 16 lines]
>
> > Cassio Tavares
Peter Duniho - 26 Jun 2007 22:25 GMT
>> the designer has to be able to instanciate the form itself for it to  
>> work in
>> the designer... if it cant do this, the form wont load
>
> So, I think the designer doesn't know what to pass in the generic
> parameter.

What generic parameter?  You specify the generic parameter in your class  
declaration.  As long as you're trying to instantiate the derived type  
rather than the generic type, I don't see how that's an issue.

Do you have a parameterless constructor for your derived type?

I understand the need for the designer to be able to instantiate the  
object, but if you have a parameterless constructor, I would think that  
would be sufficient.  If you do and it still doesn't work, I don't have an  
answer, but hopefully someone else who understands the designer better  
could explain why the designer is still having trouble, even though  
there's a parameterless constructor.

Pete
CassioT - 27 Jun 2007 05:46 GMT
Hi Pete. Yes, my constructors are parameterless. The classes are very
simple
and I already made the test. Commented all inner class code and tried
with generics
and without it. Only work without generics.

In my mind, the designer tries to instantiate the base class and fails
because it
doesn't know what to put in the generic parameter.

I hope you're right. Someone who understands the designer....

Cassio Tavares

On Jun 26, 6:25 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:

> >> the designer has to be able to instanciate the form itself for it to
> >> work in
[quoted text clipped - 17 lines]
>
> Pete
Peter Duniho - 27 Jun 2007 07:08 GMT
> Hi Pete. Yes, my constructors are parameterless. The classes are very  
> simple
> and I already made the test. Commented all inner class code and tried  
> with generics
> and without it. Only work without generics.

When you say you tested it "without generics", did you replace the generic  
base class with a different concrete class derived from Form?  Or did you  
just replace it with Form itself?

I ask because it's not clear from your description exactly how you did the  
test, and it could be that the problem you're having isn't actually  
related to generics per se.

> In my mind, the designer tries to instantiate the base class and fails  
> because it
> doesn't know what to put in the generic parameter.

But that's what I don't understand.  The base class isn't the generic  
class.  It's a fully-qualified class, just as concrete as any other  
class.  The designer doesn't need to know what to put in the generic  
parameter; you've already put that there already in your class definition.

> I hope you're right. Someone who understands the designer....

I hope so.  :)

I apologize for not trying it myself.  It's not like it would be all that  
hard to test here, but I've been spending some time trying to wrap my head  
around Apple's Cocoa programming environment, and I'm trying my best to  
not start up Windows today.  Too distracting, 'cause I wind up wasting a  
lot of time messing around with stuff that's interesting but not  
productive in the short-term.  :)

Pete
CassioT - 27 Jun 2007 13:00 GMT
Sorry Pete if I was not clear enough. The base class is the generic
class.

public BaseForm<T> : Form
{}

public MyForm : BaseForm<MyType>
{}

MyForm is the form that doesn't open in the designer. But using...

public BaseForm : Form
{}

public MyForm : BaseForm
{}

it opens.

But you made me think. :)

The base form, has the generic parameter, and opens in the
designer!!!

Maybe there is one more thing that I didn't told you. They are in
different
assemblies.

I will do more tests. I will copy all the code to the same assembly to
see what
happens.

You don't need to apologize Pete. You're already doing too much
talking with me
here. And I never heard about Apple's Cocoa before. :)

Thank you.

> > Hi Pete. Yes, my constructors are parameterless. The classes are very
> > simple
[quoted text clipped - 31 lines]
>
> Pete

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.