Link to home
Start Free TrialLog in
Avatar of Mart_dude
Mart_dude

asked on

Problem with an inherited form

In Visual Studio, I have a created a form (I shall call it formA) that uses a global data connection which is created by the MDI form. I created another form (formB), which inherits from formA. When the application runs, all works fine. However, whenever I load up the project in Visual Studio (or after I rebuild the solution), I get an error when I open formB for editing ["ExecuteReader requires an open and available Connection..."].  I inserted a bit of code in formA, to check the state of the connection and, if connection was closed, display a log on window. When I open formB for editing, the log on window is displayed.

So it appears that when I open formB for editing, it is actually executing some of the code from formA. Does anyone know why this is and how I can avoid it? I intend to have several forms inherit from formA and I would not want to receive an error message from each one on loading the project.
Avatar of theGhost_k8
theGhost_k8
Flag of India image

well as formB is inherited from formA.. it must calling the constructor... oouch i mean New() function
check if u have not written anything in New() of A..
well could u post the code where does the error occur?
ASKER CERTIFIED SOLUTION
Avatar of appari
appari
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mart_dude
Mart_dude

ASKER

I found the solution elsewhere just as appari partly gave the right answer .
By design, the form load routine of a base form will run when going to edit a form that inherits from it (I don't know what benefit this provides though). The solution is to put the code snippet offered by appari at the start of the routine that 'handles mybase.load' within the base form.