Passing value from MDI child to parent problem

I ran into a bit of a problem and looking for some help please.

I have an MDI application.
One of the Child forms has a "Browse" button that pulls up another child form with the ListBox.

The ListBox allows user to select an item by double clicking on it.
Once selected the ListBox.SelectedValue should be passed back to form's parent and the popup is closed.

I can't seem to figure out how to do it with MDI.
I tried doing it through DialogResult but .ShowDialog() isn't allowed with MDIs it seems... any help ?

Thank you in advance.
Who is Participating?
Anurag ThakurConnect With a Mentor Technical ManagerCommented:
you will have to do the following modificaitons
public delegate int ReturnedTicketNumber(string TicketNumber);

 if (FindTicketNumber==null)
           FindTicketNumber (stringTicketNumberFromListBox);

function childForm_FindTicketNumber in the main form takes an input parameter for ticketnumber
MortenSlotKristensenConnect With a Mentor Commented:
You should take a look at delegates. For instance, your could create an event in the MDI child class and make it fire the event when the an item has been selected in the list (and which item that had been selected too). Now, simply hook the event on the parent and you should be "home".

Take a look at these sites:
Hello techsuppoprt,

In your child form add the following line:

        public MDIParent1 MyParent;

In your parent form, after you call the child form, set its MyParent property to this:

        ChildFrom childForm = new ChildForm();
        childForm.MyParent = this;

You  can then use MyParent to set any public field or property on the Parent


Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Mike TomlinsonMiddle School Assistant TeacherCommented:
"I tried doing it through DialogResult but .ShowDialog() isn't allowed with MDIs it seems... any help ?"

That's can't have it as an MdiChild and use ShowDialog().

...but you can still show the "popup" using ShowDialog().  Just don't set the MdiParent() property!
Anurag ThakurTechnical ManagerCommented:
delegates and events are the way to go
when the form closes you can raise the custom event from the form closing event

have a look at the following discussions
I already proposed delegates.. :p
Anurag ThakurTechnical ManagerCommented:
yes i know but i just pointed to the solution which already exists in the EE
techsuppoprtAuthor Commented:
Thank you for your replies.

Alright, so I'm trying to make it work with events but need a little push...

So the main form has a public property called TicketNumber which should get the Value from the selected item on the child LIstBox popup form. The child popup is triggered by the BUtton click from the parent.


I created the event on the child Popup ( within the class):

        public delegate int ReturnedTicketNumber();
        public event ReturnedTicketNumber FindTicketNumber;

On the ListBox double click event ( which should return the SelectedValue I added:

            if (FindTicketNumber==null)

Then in the Main Form I added the following under the Button click event:

ChildPopupForm childForm=new ChildPopupForm ();
childForm.MDIParent = this.MDIParent;

childForm.FindTicketNumber+= new  ChildPopupForm.ReturnedTicketNumber(childForm_FindTicketNumber);

At this point I'm confused .. How am I getting the selected Value from the ListBox after all ? :-/
techsuppoprtAuthor Commented:
hmmm.. for some reason the event never gets triggered as it is never Null.

Any idea ?
DabasConnect With a Mentor Commented:
if (FindTicketNumber!=null)
techsuppoprtAuthor Commented:
Thanks guys.

Ragi, was that just a typo ?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.