Communication between forms

  • Thread starter Thread starter Selva Chinnasamy
  • Start date Start date
S

Selva Chinnasamy

I have multiple Mdi Child forms.

Form1 is displaying all the orders list,
Form2 is displaying all the product list.

When I rename a Product name on Form3, I wanted to update contents in Form1
and 2.

Right now the Function renaming the Product is calling
reload functions in Form1 and 2, but its not refreshed.

Thanks In advance for your help.
 
You may want to look into the concepts of delegates and events... Its more
like when you click a button, you write code in response to the click, in
the click event. So you will write a delegate/event in Form3 and subscribe
that in Form1 and Form 2, to perform the update in the notification event.
you have to implement this event for your product object... and since
product object is sued in Form 1 and Form 2, you can subscribe to it in the
Form and perform the action on the update event... Codeproject.com or any
vbproject samples websites have simple samples that explain the concept....,
if you google you will get them

VJ
 
Hi Selva,
Thank you for posting. From your post, my understanding on this issue is:
how to update contents in Form1 and Form2 when the Product name in Form3
changed. If I'm off base, please feel free to let me know.

You can define an event for the change of the product name and write a
method to trigger the event when the product name changes in Form3. Then
subscribe the event and define corresponding event handling methods in
Form1 and Form2. Thus when the product name in Form3 changes, the event
will be raised and the corresponding event handling methods in Form1 and
Form2 will be called.
The following is a sample.

// event defined in Form3
public delegate void ProductNameChangedEventHandler(int productID);
public event ProductNameChangedEventHandler EvtProductNameChanged;
private void OnProductNameChanged(int id)
{
if (EvtProductNameChanged != null)
{
EvtProductNameChanged(id);
}
}

// add reference variable of a instance of Form3 ,subscribe the event and
define the handling method
public Form3 frm3 = null;
public Form1()
{
InitializeComponent();
frm3.EvtProductNameChanged += new
Form3.ProductNameChangedEventHandler(frm3_EvtProductNameChanged);
}
void frm3_EvtProductNameChanged(int productID)
{
// add your update process here
}

You should assign the instance of Form3 to the reference variable "frm3"
of Form1 in the MDI Parent.

Hope this is helpful to you.
Please don't hesitate to tell me if you have any other concerns, or need
anything else.


Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
 
Hi Linda,

Thanks for your post. It is helpful to me as well. I'm not that strong
on delegates.

But since this is a VB newsgroup, could you explain how the same thing
would be done in VB.NET ? Would it be as simple as converting the code
to VB.NET ?

Thanks in advance,

Regards,

Cerebrus.
 
Hi Cerebrus,

The following is a sample written in VB.NET.
// event defined in Form3
Public Event EvtProductNameChanged(ByVal productID As Integer)
Private Sub OnProductNameChanged(ByVal id As Integer)
RaiseEvent EvtProductNameChanged(id)
End Sub

// add reference variable of a instance of Form3 , define the event
handling method
Public WithEvents frm3 As Form3
Private Sub frm3_EvtProductNameChanged(ByVal productID As Integer)
Handles frm3.EvtProductNameChanged
' add your update process here
End Sub

You should assign the instance of Form3 to the reference variable "frm3"
of Form1 in the MDI Parent.
Hope this is helpful to you.

Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
 
Hi Cerebrus, you're welcome!


Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
 
Hi Selva,

You are welcome!
If you have any other questions or concerns, please don't hesitate to
contact us. It is always our pleasure to be of assistant.

Have a nice day!


Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
 
Back
Top