473,394 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

inherit form and generics

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

Jun 26 '07 #1
6 3048
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

"CassioT" <ca*****@gmail.comwrote in message
news:11**********************@q69g2000hsb.googlegr oups.com...
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

Jun 26 '07 #2

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.
On 26 jun, 17:39, "Smokey Grindle" <nos...@nospam.comwrote:
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

"CassioT" <cass...@gmail.comwrote in message

news:11**********************@q69g2000hsb.googlegr oups.com...
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

Jun 26 '07 #3
On Tue, 26 Jun 2007 14:12:47 -0700, CassioT <ca*****@gmail.comwrote:
On 26 jun, 17:39, "Smokey Grindle" <nos...@nospam.comwrote:
>>
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, \0ven though
there's a parameterless constructor.

Pete
Jun 26 '07 #4
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:
On Tue, 26 Jun 2007 14:12:47 -0700, CassioT <cass...@gmail.comwrote:
On 26 jun, 17:39, "Smokey Grindle" <nos...@nospam.comwrote:
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

Jun 27 '07 #5
On Tue, 26 Jun 2007 21:46:10 -0700, CassioT <ca*****@gmail.comwrote:
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
Jun 27 '07 #6
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.

On 27 jun, 03:08, "Peter Duniho" <NpOeStPe...@nnowslpianmk.comwrote:
On Tue, 26 Jun 2007 21:46:10 -0700, CassioT <cass...@gmail.comwrote:
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

Jun 27 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Bernardo Heynemann | last post by:
How can I use Generics? How can I use C# 2.0? I already have VS.NET 2003 Enterprise Edition and still can´t use generics... I´m trying to make a generic collection myCollection<vartype> and...
6
by: Mohammad-Reza | last post by:
I wrote a component using class library wizard. In my component i want to in order to RightToLeft property do some works. I can find out if user set this property to Yes or No, But if He/She set it...
44
by: Frank Rizzo | last post by:
Any ideas?
4
by: David | last post by:
I have trying to have a webform inherit controls from another form and can't get it to work Say I have a form that saves the person's demographic info. ****one.aspx**** //I have an object...
2
by: Wu Qinliang | last post by:
I created a Windows form named myform1, and put some controls on it. I need another form named myform2. Because myform2 is similar to myform1, so I want myform2 to inherit from myform1, i.e: ...
23
by: Luc Vaillant | last post by:
I need to initialise a typed parameter depending of its type in a generic class. I have tried to use the C++ template form as follow, but it doesn't work. It seems to be a limitation of generics...
12
by: Michael S | last post by:
Why do people spend so much time writing complex generic types? for fun? to learn? for use? I think of generics like I do about operator overloading. Great to have as a language-feature, as...
9
by: sloan | last post by:
I'm not the sharpest knife in the drawer, but not a dummy either. I'm looking for a good book which goes over Generics in great detail. and to have as a reference book on my shelf. Personal...
13
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.