942,788 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 2455
  • C# RSS
Nov 26th, 2009
0

call function in childform from mdi parent

Expand Post »
hi
i have function in mdiparent form and i want to use it in child form.
i created an object reference of parent form in child form and tried to call the function but this didnt worked.
wat should i do??
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
plastic is offline Offline
13 posts
since Nov 2009
Nov 26th, 2009
0
Re: call function in childform from mdi parent
First of all, C# doesnt have functions, they are methods. I'm on a crusade to eradicate that word from this board

Secondly, how is the method declared, private/public/protected? How have you created your reference to the parent form?
Reputation Points: 512
Solved Threads: 246
Nearly a Posting Virtuoso
Ryshad is offline Offline
1,260 posts
since Aug 2009
Nov 26th, 2009
0
Re: call function in childform from mdi parent
kkk its method..
i declared the method as public in parect form
and used the follwing code to call the method in child form
Form1 ob1 = new Form1();//form1 is parent form
ob1.alllblvis();//alllvlvis is the function
Reputation Points: 10
Solved Threads: 0
Newbie Poster
plastic is offline Offline
13 posts
since Nov 2009
Nov 26th, 2009
0
Re: call function in childform from mdi parent
Theres your problem. You arent getting a reference to your original Form1, you are creating a new one.
You need to get a reference to the original form if you want to effect any changes to it:
C# Syntax (Toggle Plain Text)
  1. Form1 parent = (Form1)this.MdiParent;
  2. parent.alllblvis();

You need to ensure you have set the MDIParent of the second form when you called it:

C# Syntax (Toggle Plain Text)
  1. Form2 newForm = new Form2();
  2. newForm.MdiParent = this;
  3. newForm.Show();
Reputation Points: 512
Solved Threads: 246
Nearly a Posting Virtuoso
Ryshad is offline Offline
1,260 posts
since Aug 2009
Nov 26th, 2009
0
Re: call function in childform from mdi parent
hi
i used the second code to make form 1 the parent of the form2 and show it. But the first form in giving an error. its asking for ';' after the 'this' of the first line. i.e. this;mdiparent
Reputation Points: 10
Solved Threads: 0
Newbie Poster
plastic is offline Offline
13 posts
since Nov 2009
Nov 26th, 2009
0
Re: call function in childform from mdi parent
Post the code in question, or zip up the project so we can see what is happening.
Reputation Points: 341
Solved Threads: 233
Posting Shark
DdoubleD is offline Offline
984 posts
since Jul 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: WPF UserControl MouseEvents to Winform
Next Thread in C# Forum Timeline: Check if record exists in MSA using C#





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC