*Experts* DiverDan Posted February 3, 2003 *Experts* Posted February 3, 2003 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. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
*Experts* Nerseus Posted February 3, 2003 *Experts* Posted February 3, 2003 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 Quote "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* DiverDan Posted February 3, 2003 Author *Experts* Posted February 3, 2003 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? Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Cywizz Posted February 3, 2003 Posted February 3, 2003 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 Quote Howzit??
*Experts* Nerseus Posted February 3, 2003 *Experts* Posted February 3, 2003 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 Quote "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* divil Posted February 3, 2003 *Gurus* Posted February 3, 2003 (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 February 3, 2003 by divil Quote 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* Nerseus Posted February 3, 2003 *Experts* Posted February 3, 2003 D'oh! I meant fields. Sorry - you can define properties, just not fields. For example: public string Test; -nerseus Quote "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* divil Posted February 3, 2003 *Gurus* Posted February 3, 2003 Aaah, makes sense now :) Quote 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* DiverDan Posted February 4, 2003 Author *Experts* Posted February 4, 2003 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? Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Cywizz Posted February 4, 2003 Posted February 4, 2003 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) Quote Howzit??
*Experts* DiverDan Posted February 4, 2003 Author *Experts* Posted February 4, 2003 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? Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
*Experts* Nerseus Posted February 4, 2003 *Experts* Posted February 4, 2003 When you complete the calculations. -ner Quote "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
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.