microkarl Posted August 3, 2006 Posted August 3, 2006 Hi, I have two windows forms written in C#. The parent form can call the child form to open. In the child form, I have logic to add/remove certain nodes in a XML document. After that, I can close the child form. But I also have listbox control in the parent form to display the items from the exact XML document, since I have updated it, I would like to 'reload' the control so it will display the most updated list. But how do I do it? I suppose I can fire an event on the childform.Close() event, and use this.ParentForm to do it? But I could not see any functions in the parent form. please help. Quote Donald DUCK : YOU ARE FIRED!!!
Cags Posted August 3, 2006 Posted August 3, 2006 If the child form is called using the ShowDialog() method then the code will resume in the parent form directly after the ShowDialog() line and you can just call a ReloadXML() method from there. Of course this assumes you don't use the parent form before the child form is closed. If you need to allow both forms to be used concurrently then one way of doing it would be to pass a reference to the parent form into the child forms constructor. public class ParentForm : System.Windows.Forms.Form { public ParentForm() { } private void CreateChildForm() { ChildForm myChild = new ChildForm(this); } public void ReloadXML() { // reload the xml and populate the listbox } } public class ChildForm : System.Windows.Forms.Form { private ParentForm _parent; public ChildForm(ParentForm parent) { _parent = parent; } private ChangeXML() { // alter the xml file // update the parent _parent.ReloadXML(); } } Quote Anybody looking for a graduate programmer (Midlands, England)?
microkarl Posted August 3, 2006 Author Posted August 3, 2006 Thanks, it works fine!! Quote Donald DUCK : YOU ARE FIRED!!!
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.