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 / Windows Forms / WinForm General / September 2004

Tip: Looking for answers? Try searching our database.

Exception trying to instansiate an inherited form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ron L - 29 Sep 2004 17:59 GMT
I have created a form for my application.  Once the form was working, I
copied that form to a new form that would contain all the common elements of
all forms in my application and made the existing form inherit from the
common one.  Now when I try to run my application I get the following error
when I open the form:

An exception occurred while trying to create an instance of
WebWinFormTry1.frmNITSSForm. The exception was "Constructor on type
MyAppTest.frmParentForm not found.".

The relevant code for the 2 classes is included below.  Can anyone tell me
what I am doing wrong here.  As far as I can tell, I have the constructor
for both defined.

TIA
Ron L

frmParentForm.vb:

Option Strict On

Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data.OleDb

Public Class frmParentForm
   Inherits System.Windows.Forms.Form

   Protected frmMain As myAppMain
   Protected textIsDirty As Boolean

#Region " Windows Form Designer generated code "

   'Public Sub New() ' Default constructor not implemented.  Need to pass
the parent form in to work.
   '    MyBase.New()

   '    'This call is required by the Windows Form Designer.
   '    InitializeComponent()

   '    'Add any initialization after the InitializeComponent() call

   'End Sub

   Public Sub New(ByRef frmMainNew As myAppMain)
       MyBase.New()

       'This call is required by the Windows Form Designer.
       InitializeComponent()

       'Add any initialization after the InitializeComponent() call
       frmMain = frmMainNew
       Call BindAndLoadControls()
   End Sub

   'Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub

   'Required by the Windows Form Designer
... code removed for brevity
#End Region

... other common functions here

End Class

frmChildForm.vb:
Option Strict On

Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data.OleDb

Public Class frmUserAdmin
   Inherits MyAppTest.frmParentForm

   Private dsUserList As New DataSet
   Private dsUserData As New DataSet
   Private dsPermissions As New DataSet
   Private permsList As DataTable

#Region " Windows Form Designer generated code "

   'Public Sub New() 'Default constructor not implemented.  Need to pass in
main form to work.
   '    MyBase.New()

   '    'This call is required by the Windows Form Designer.
   '    InitializeComponent()

   '    'Add any initialization after the InitializeComponent() call

   'End Sub

   Public Sub New(ByRef frmMainNew As NITSSMain)
       MyBase.New(frmMainNew)

       'This call is required by the Windows Form Designer.
       InitializeComponent()

       'Add any initialization after the InitializeComponent() call
       frmMain = frmMainNew
       Call BindAndLoadControls()
   End Sub

   'Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub

   'Required by the Windows Form Designer
... Code removed for brevity

#End Region

... code removed for brevity
End Class
Sijin Joseph - 29 Sep 2004 18:18 GMT
You parent form needs to have a default constructor explicitly defined.
i.e  a constructor that takes no parameter.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> I have created a form for my application.  Once the form was working, I
> copied that form to a new form that would contain all the common elements of
[quoted text clipped - 131 lines]
> ... code removed for brevity
> End Class
Ron L - 29 Sep 2004 18:32 GMT
Sijin
   Thanks for the response.  I had tried that before with no luck, but I
tried again.  I get the same error with both constructors.  Do you have any
other suggestions?

Ron L

> You parent form needs to have a default constructor explicitly defined.
> i.e  a constructor that takes no parameter.
[quoted text clipped - 138 lines]
>> ... code removed for brevity
>> End Class
Sijin Joseph - 30 Sep 2004 08:01 GMT
Hi Ron,

Where is the code for the class WebWinFormTry1.frmNITSSForm the error is
being thrown for that class?

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> Sijin
>     Thanks for the response.  I had tried that before with no luck, but I
[quoted text clipped - 145 lines]
>>>... code removed for brevity
>>>End Class
Ron L - 30 Sep 2004 12:46 GMT
Sijin
   I just realized <embarrased> that the "error" I was seeing was the #$$%^
task list.  However, I do have a problem with the form in design view.  When
I try to look at the child form frmChildForm [Design] in the IDE I get the
following error message:

   An error occurred while loading the document.  Fix the error, and then
try loading the document again.  The error message follows:
       Object reference not set to an instance of an object

Thanks and sorry for the red herring.

Ron L

> Hi Ron,
>
[quoted text clipped - 156 lines]
>>>>... code removed for brevity
>>>>End Class
Sijin Joseph - 30 Sep 2004 13:15 GMT
Does the error in Design View occur even after writing a default
constructor for the child form?

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> Sijin
>     I just realized <embarrased> that the "error" I was seeing was the #$$%^
[quoted text clipped - 170 lines]
>>>>>... code removed for brevity
>>>>>End Class
Ron L - 30 Sep 2004 13:36 GMT
Yes.

Ron L

> Does the error in Design View occur even after writing a default
> constructor for the child form?
[quoted text clipped - 177 lines]
>>>>>>... code removed for brevity
>>>>>>End Class

Rate this thread:







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.