Error inheriting a form with a parameter

G

Greg Smith

I am attempting to inherit a form that has a parameter passed to it:

public frmListbox_c0(string strConnectionString)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}

The form tests successfully if included in a program but when inherited for
a class library it gets the error:

"An exception occurred while trying to create an instance of
Listbox.frmListbox_c0. The exception was "Constructor on type
Listbox.frmListbox_c0 not found.".



Is this a do-able thing?



Any help is greatly appreciated.
 
J

James Bender

Well, I know it's doable, because I am doing (a lot of)
it!

Is the problem happening when you are tying to create the
inherited form? If so, does the class library you are
trying to create the form in have a reference to the
assembly/project that the ancestor form is in?

In general this is very doable, however the visual
designer in VS.Net is kinda picky about it. To get your
form to display in the designer for visual editing, you
have to maintain an overloaded constructor with no
arguments with a call to the InitializeComponent method.
I think this is because the designer tries to "build" the
form when it displays, and if it doesn't have a value for
the constructor argument. I have noticed the same problem
if you try to make a form abstract.
 

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