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.
LVL 1
techsuppoprtAsked:
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
0
 
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:
http://www.akadia.com/services/dotnet_delegates_and_events.html
http://msdn.microsoft.com/en-us/library/ms173172.aspx
http://www.c-sharpcorner.com/UploadFile/Ashush/Delegates02152008155757PM/Delegates.aspx
0
 
DabasCommented:
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;
        childForm.Show();

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


Regards,

Dabas
0
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 right...you 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!
0
 
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
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_CSharp/Q_23736959.html
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_CSharp/Q_23795439.html
0
 
MortenSlotKristensenCommented:
ragi0017:
I already proposed delegates.. :p
0
 
Anurag ThakurTechnical ManagerCommented:
yes i know but i just pointed to the solution which already exists in the EE
0
 
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.

So...

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


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);
childForm.Show();

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

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

Ragi, was that just a typo ?
0
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.