By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,694 Members | 1,307 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,694 IT Pros & Developers. It's quick & easy.

Inheritance Question in VB.NET

P: n/a
Hi
I am new to VB.NET and I am trying to figure out how to exchange data
between 2 forms based on parent-child relationship between 2 forms. Form2 is
child of form1. In form1.vb, I am doing
Dim t As New Form2
t.Show()

This is really strange to me because by OOPS, a base class has no knowledge
of the child class and should be able to instantiate a child class object.

Can someone explain this? Also, can someone suggest a better way to exchange
data between 2 forms.

Regards

Saumitra
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Dim t As New Form2
t.mdiparent = me
t.Show()

Saumitra wrote:
Hi
I am new to VB.NET and I am trying to figure out how to exchange data
between 2 forms based on parent-child relationship between 2 forms. Form2 is
child of form1. In form1.vb, I am doing
Dim t As New Form2
t.Show()

This is really strange to me because by OOPS, a base class has no knowledge
of the child class and should be able to instantiate a child class object.

Can someone explain this? Also, can someone suggest a better way to exchange
data between 2 forms.

Regards

Saumitra


Nov 21 '05 #2

P: n/a
Ahhh, what you are talking about "parent<-->child" relationship between
forms is not the same as inheritance. In OOP, inheritence refers to the
fact that the methods, properties and member variables of a class are
"inherited" by the new class at compile time, whereas the Window Parent <->
Child relationship purely refers to the fact that one recieves messages from
the other. Your Form1 will contain a reference to your Form2 and your Form2
will contain a reference (parent) to your Form1. Both of the classes you
are using are derived from Windows.Forms, not from each other.

"Saumitra" <Sa******@discussions.microsoft.com> wrote in message
news:14**********************************@microsof t.com...
Hi
I am new to VB.NET and I am trying to figure out how to exchange data
between 2 forms based on parent-child relationship between 2 forms. Form2
is
child of form1. In form1.vb, I am doing
Dim t As New Form2
t.Show()

This is really strange to me because by OOPS, a base class has no
knowledge
of the child class and should be able to instantiate a child class object.

Can someone explain this? Also, can someone suggest a better way to
exchange
data between 2 forms.

Regards

Saumitra

Nov 21 '05 #3

P: n/a
"Saumitra" <Sa******@discussions.microsoft.com> schrieb:
I am new to VB.NET and I am trying to figure out how to exchange data
between 2 forms based on parent-child relationship between 2 forms. Form2
is
child of form1. In form1.vb, I am doing
Dim t As New Form2
t.Show()

This is really strange to me because by OOPS, a base class has no
knowledge
of the child class and should be able to instantiate a child class object.


Inheritance <> Parent <-> child relationship!

What you need is a reference to your instance of the form you want to
manipulate. There are different ways to make this reference available, for
example, by passing it in method parameters or assigning it to properties,
or implementing the Singleton design pattern if there can be only one
instance of a form:

Providing a reference to an application's main form
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=accessmainform&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.