Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted
I have a parent form that performs various calculations. I would like to know how to pass the results to the ActiveMdiChild's listview. Since there might be several MDIChild forms created, it is important that the results are only passed to the listview of the ActiveMdiChild.

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

  • *Experts*
Posted

You have a couple of options...

First, do you really want the parent to pass data to the child, or have the active child "pull" something from the parent?

 

If you really want the parent form to pass data to the active child window, you'll need to somehow get a specific interface to the child. If you know that all of the child windows are of type Class2 for instance, you can cast the ActiveMdiChild property as Class2 and then call any public methods on that form:

// From the parent form...
((Class2)this.ActiveMdiChild).SetSpecialData(this.myDataSet);

 

You can also define an interface that all child forms inherit. As above, you can cast the child form as the interface to make the function call. For example:

// Define the interface:
public interface ISpecialForm
{
public void SetSpecialData(object data);
}

// In Class2, a child form:
public class Class2 : System.Windows.Forms.Form, ISpecialForm
{
public void SetSpecialData(object data)
{
	// Receive the data...
}
}

// From within the MDIParent form:
((ISpecialForm)this.ActiveMdiChild).SetSpecialData(this.myDataSet);

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted
Okay...can you translate this into VB.net lingo so that I do not misunderstand anything you have written. And pulling from the active child is new to me. Would this be a better option? If all the child forms are created from the same form then would all child forms receive the calculated data? All the action takes place when a calculate button is pressed. With this specific event can pulling from the parent be more effictive then passing to the active child?

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

Hi

 

Translates to:

 

' From the parent form...
CType(me.ActiveMdiChild, Class2).SetSpecialData(me.myDataSet)

 

and..

 

' Define the interface:
Public Interface ISpecialForm

   Function SetSpecialData(data as Object);

End Interface

' In Class2, a child form:
Public Class Class2
 Inherits System.Windows.Forms.Form
 Implements ISpecialForm

   Public Function SetSpecial() As Object Implements Class1.SetSpecial

' Receive the data...

   End Function        


' From within the MDIParent form:
CType(me.ActiveMdiChild,ISpecialForm).SetSpecialData(me.myDataSet)

 

I suggest you use Nerseus's example above and create all child mdichild forms, implementing this type of interface.

This way you will know that all child forms will have the 'SetSpecialData' function. (Note you can obviosly change it to a property)

 

You can also use events and delegates in this senario. You can, on creation of these mdichildren, let them subscribe to a parent event, that gets fired when you want to pass the data. This will however fire onto all subscribed children, not just the activechild.

 

Hope this helps

Howzit??
  • *Experts*
Posted

Thanks for the VB conversion :)

 

One note:

This way you will know that all child forms will have the 'SetSpecialData' function. (Note you can obviosly change it to a property)

 

I don't know about VB.NET, but interfaces can't implement properties in C#.

 

-nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Gurus*
Posted (edited)

Can you explain what you mean, Nerseus? I've had no problem defining properties in a C# interface.

 

public interface ITest {
   string Test { get; }
}

 

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfinterfaceproperties.asp

Edited by divil

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

  • *Experts*
Posted

D'oh! I meant fields. Sorry - you can define properties, just not fields. For example:

 

public string Test;

 

-nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted
Thanks for the help....but I am a bit too new to VB to totally understand and implement this. Could you make it a bit more plan for me? If I add the define code to all childs and the CType Dataset code in the parent...then how can I pass the information to the ActiveMdiChild listview?

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

Well this piece of code:

 

' From within the MDIParent form:
CType(me.ActiveMdiChild,ISpecialForm).SetSpecialData(me.myDataSet)

 

will pass the information to the active child.

 

Note that the example given to you will pass a dataset to the child, but you can use any type of data format (array's, hastable, etc... whichever makes more sense in your design)

Howzit??
  • *Experts*
Posted
Thanks...Do I put this call when I create the MdiChild, or when I complete the calculations and need to pass the results to the MdiChild?

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

  • *Experts*
Posted

When you complete the calculations.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...