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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
"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!
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

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 ? :-/
Anurag ThakurTechnical 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
techsuppoprtAuthor Commented:
hmmm.. for some reason the event never gets triggered as it is never Null.

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

Ragi, was that just a typo ?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.