Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Passing value from MDI child to parent problem

Posted on 2008-11-07
11
Medium Priority
?
1,222 Views
Last Modified: 2013-12-17
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.
0
Comment
Question by:techsuppoprt
  • 3
  • 3
  • 2
  • +2
11 Comments
 
LVL 2

Assisted Solution

by:MortenSlotKristensen
MortenSlotKristensen earned 600 total points
ID: 22909132
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
 
LVL 27

Expert Comment

by:Dabas
ID: 22909166
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 22909400
"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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22912295
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
 
LVL 2

Expert Comment

by:MortenSlotKristensen
ID: 22912353
ragi0017:
I already proposed delegates.. :p
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22912429
yes i know but i just pointed to the solution which already exists in the EE
0
 
LVL 1

Author Comment

by:techsuppoprt
ID: 22932820
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
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 1200 total points
ID: 22932910
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
 
LVL 1

Author Comment

by:techsuppoprt
ID: 22933560
hmmm.. for some reason the event never gets triggered as it is never Null.

Any idea ?
0
 
LVL 27

Assisted Solution

by:Dabas
Dabas earned 200 total points
ID: 22933803
if (FindTicketNumber!=null)
0
 
LVL 1

Author Closing Comment

by:techsuppoprt
ID: 31514556
Thanks guys.

Ragi, was that just a typo ?
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month21 days, 5 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question