G
Gary Shell
I have jumped in to the deep end of the pool, trying out visual inheritance
of a form and have run into a snag.
I have the need to create a simple maintenance form for five identically
configured database files. (The only difference in the tables is their name
and keyfield name.) Hmmm, I though, a perfect candidate for trying our
Visual Inheritance for the first time. ARGHHHHHHH! What have I gotten
myself into?
Here's the specifics. I created a form and saved it as a class. I am able
to then create a form that inherits my original. That part works great. I
was even able to add a couple of Protected Strings to the base form and in
the Public Sub New routine of the one of the real forms I added code to set
the two protected strings to reflect the Table name and Key name. The form
load event in the base form uses these strings to dynamically create the SQL
Data adapters SQLSelectCommand, the SQLEditCommand, SQLInsertCommand etc. I
even got the base form code to modify the BindingContext so the update and
inserts worked flawlessly.
The base form has a dataset defined on it. I was HOPING to modify the code
for the dataset so that I could use the same Table Name and Key Name fields
to dynamically create the dataset like I was able to do with the
SqlDataAdapter's command strings. My real form inherits the base form,
initializes a base form instance and then sets my two protected strings in
the base form. Thusly:
Public Class frmIOClass
Inherits TheClassForm.frmTheClass
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
'*gs* These override the Protected strings in the base class
' of this form.
MyClass.strTheTable = "Input_Output_Class"
MyClass.strTheKey = "IOClass"
End Sub
Then in the load event of the baseform the code executes to generate the
SQLDataAdapter command strings. I tried putting code in the load event that
would populate some Protected strings in the dataset class code module. But
I soon realized that was WAY too late. The initialization code for the
dataset class was executed when the base form itself was initialized. It
was at that time that the dataset class was instantiated.
I'm stumped. I can't figure out how to get the Private strings set with the
Table Name and Key Name in the dataset class code BEFORE the dataset class
initialization code executes. I found the code in the base form that
actually instantiates the dataset. Here is a bit of that code:
Friend WithEvents dsTheClass As TheClassForm.dsTheClass
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New
System.Resources.ResourceManager(GetType(frmTheClass))
Me.txtTheClassName = New System.Windows.Forms.TextBox
Me.dsTheClass = New TheClassForm.dsTheClass
Me.txtTheClassDescription = New System.Windows.Forms.TextBox
Me.btnCancel = New System.Windows.Forms.Button
Me.btnOK = New System.Windows.Forms.Button
Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlDeleteCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlUpdateCommand1 = New System.Data.SqlClient.SqlCommand
CType(Me.dsTheClass, System.ComponentModel.ISupportInitialize).BeginInit()
I thought I could sneak in the code to set some private strings in the
dataset class right after the "Me.dsclass = New TheClassForm.dsClass" line
of code, but apparently VB wasn't kidding when I read the comment in the
code admonishing me as follows:
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Any code I try to add there gets "eaten" by the IDE. So I've hit the
proverbial brick wall. Anybody tried to tackle this before? Anyone have
any pearls of wisdom that they might share on this topic?
Thanks,
Gary Shell
of a form and have run into a snag.
I have the need to create a simple maintenance form for five identically
configured database files. (The only difference in the tables is their name
and keyfield name.) Hmmm, I though, a perfect candidate for trying our
Visual Inheritance for the first time. ARGHHHHHHH! What have I gotten
myself into?
Here's the specifics. I created a form and saved it as a class. I am able
to then create a form that inherits my original. That part works great. I
was even able to add a couple of Protected Strings to the base form and in
the Public Sub New routine of the one of the real forms I added code to set
the two protected strings to reflect the Table name and Key name. The form
load event in the base form uses these strings to dynamically create the SQL
Data adapters SQLSelectCommand, the SQLEditCommand, SQLInsertCommand etc. I
even got the base form code to modify the BindingContext so the update and
inserts worked flawlessly.
The base form has a dataset defined on it. I was HOPING to modify the code
for the dataset so that I could use the same Table Name and Key Name fields
to dynamically create the dataset like I was able to do with the
SqlDataAdapter's command strings. My real form inherits the base form,
initializes a base form instance and then sets my two protected strings in
the base form. Thusly:
Public Class frmIOClass
Inherits TheClassForm.frmTheClass
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
'*gs* These override the Protected strings in the base class
' of this form.
MyClass.strTheTable = "Input_Output_Class"
MyClass.strTheKey = "IOClass"
End Sub
Then in the load event of the baseform the code executes to generate the
SQLDataAdapter command strings. I tried putting code in the load event that
would populate some Protected strings in the dataset class code module. But
I soon realized that was WAY too late. The initialization code for the
dataset class was executed when the base form itself was initialized. It
was at that time that the dataset class was instantiated.
I'm stumped. I can't figure out how to get the Private strings set with the
Table Name and Key Name in the dataset class code BEFORE the dataset class
initialization code executes. I found the code in the base form that
actually instantiates the dataset. Here is a bit of that code:
Friend WithEvents dsTheClass As TheClassForm.dsTheClass
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New
System.Resources.ResourceManager(GetType(frmTheClass))
Me.txtTheClassName = New System.Windows.Forms.TextBox
Me.dsTheClass = New TheClassForm.dsTheClass
Me.txtTheClassDescription = New System.Windows.Forms.TextBox
Me.btnCancel = New System.Windows.Forms.Button
Me.btnOK = New System.Windows.Forms.Button
Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlDeleteCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlUpdateCommand1 = New System.Data.SqlClient.SqlCommand
CType(Me.dsTheClass, System.ComponentModel.ISupportInitialize).BeginInit()
I thought I could sneak in the code to set some private strings in the
dataset class right after the "Me.dsclass = New TheClassForm.dsClass" line
of code, but apparently VB wasn't kidding when I read the comment in the
code admonishing me as follows:
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Any code I try to add there gets "eaten" by the IDE. So I've hit the
proverbial brick wall. Anybody tried to tackle this before? Anyone have
any pearls of wisdom that they might share on this topic?
Thanks,
Gary Shell