Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Donald DUCK : YOU ARE FIRED!!!
Posted

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();
   }
}

Anybody looking for a graduate programmer (Midlands, England)?

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...