Visual inheritance not working

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I had 2 forms inheriting from a base one. It all worked nicely to start off
with. Don't know what I did next (did some code in the base form), because
now the VS IDE doesn't want to open either of the child forms.

It complains about "ConnectionString property has not been initialized".
I'm tryig to build a 3 tier application so there is no DB connections on
mypresentation layer. But then, I just started C# so am probably missing
something obvious. The same error also displays when I try to create a new
form from the base.

Another thing to note is that the inherited forms work when I execute the
code. It is just in the IDE where I get the problem. I'll send code to
anyone who volunteers to help.

Thanks
 
A couple things to know about form inheritance and the designer ...

1) The designer will instantiate your base form. This means the base form's
constructor will be called. (I think this is true... it's all very
compicated and I may not have it quite right...) If you use the derived form
in code (but do not instantiate the base form), then only the derived form's
constructor will be called. So possibly you have something that needs to be
initialized in order for the base form to be shown, but you're only
initializing it in the derived form?

2) There seems to be a weird restriction on the designer that if you have a
certain name that gets inherited, you can not name anything else in your
project by the same name, or by a name that differs only in casing... That
is, if you have a form with a derived control MyControl, you will have a
conflict (according to the designer) if a different form (not derived from
the same base) has something named myControl. There is no reason in C# these
should conflict, but the designer can't deal with it. (At least, mine
can't.)

3) This is something I've run across, not specifically about form
inheritance, and I see it as a bug, so maybe in some other version it's
fixed, but does seem to be a desiger issue...
If you have a property defined in an interface with only a "get", but define
a class that has a "get" and a "set" on that property, it will compile (and
I think should be fine, since interface only defines a subset of the
functions in a class.) However, if you have a component or control that
implents the property as read/write, the designer says you have conflicting
definitions (I guess it sees read only property as fundamentally different
from read/write property.)

Hope this helps,
Rachel
 
Thanks to Rachel for the quick response, although I could still not find the
problem. As promised the code was sent to your email address.
Thanks in advance
 
JD,

Could it be that some data binding you've done on the form relies on a DB
connection at design time to show your data binding options, and is unable
to estalish that?

--Bob
 
I don't think the IDE should be trying to establish DB connections at design
time.

Here is the code that connects to my Business tier - > linking to my Data
Tier.
private void FeeBase_Load(object sender, System.EventArgs e)
{
FeeInfoCollection fic = new FeeInfoCollection();
// Fill the collection from the DB
fic.GetFees();
this.dgFees.DataSource = fic;
}
 
.. As promised the code was sent to your email address.
Thanks in advance

Sorry, I can not debug your ap for you. Even if I wanted to, my system does
not support Microsoft Access database. Here are a coupla things you might
try ...

A) Try to find the simplest possible project or solution that will reproduce
your problem. In doing so, you'll probably figure out what it is.

B) You can set breakpoints to debug code in design mode as follows (assuming
you are using VS)...
(1) Open the solution and select the project where the base form
is defined in one instance of VS
(2) Go to Project->Properties->Configuration Properties->Debugging
(a) Set "Debug Mode" to "Program"
(b) Set Start Application to devenv.exe (you may need
to supply path)
(c) Set Command Line Arguments to the *.sln file for your test ap
(can be the same solution you're in, that's fine.)
(3) RightClick on project & choose "Set as Startup Project"

Now when you F5 to debug, A new instance of VS will be started.
You can try adding an inherited form to that project and see if any
breakpoints get hit...

Hope this helps...
-Rachel
 
Thanks Rachel & Bob

It did turn out that the inherited forms call the Load event of the Base
form and thus tried to connect to the DB at design time.

I find this a bit weird, but at least the problem is gone. Testing if I'm
in design mode now before calling th eDB connection code.

Cheers
 
Back
Top