|
Hi,
I am trying to execute a method from child form.
MainForm myForm = new MainForm(); // MainForm is the name of the parent form
myForm.refreshLetterBindingSource();
But neither its showing any error, not its executing the method. Can u give me any idea please how to call method in parents Form from Child ?
-- modified at 3:53 Sunday 12th February, 2006
|
|
|
|
|
Dear
u must place code in MainFrom:
ChildForm child=new ChildForm;//in mainForm
child.MdiParent=this;//(this) is yourMainForm
u must place code in ChildForm:
(this.Owner as MainForm).refreshLetterBindingSource();
//cast to MainForm and call method;
if u need anything with .net,mail to me
buccaminh12@yahoo.com
|
|
|
|
|
Hello ,
Thanks a loot for the response. but what if i dont want to make parent form MDI container. Is not it possible to call method in parent form without MDI container declaration ?
Thanks
|
|
|
|
|
Make sure that when the parent form creates the child form, it sets the child form's Owner property to 'this' (this parent form instance).
ChildForm childForm = new ChildForm();
childForm.Owner = this;
childForm.Show();
Then in the child form you simply cast the Owner property to a MainForm and call your method.
MainForm parent = this.Owner as MainForm;
parent.SomeMethod();
The problem with your initial code sample is that it creates a new instance of MainForm, which is not the same instance as the actual parent form.
Josh
|
|
|
|
|
Thanks a loot. Exactly this snippet i was looking for. I will test it and If I face error, I will let u know.
thanks again
Emran
|
|
|
|
|
Thanksssssssssssss a loooooooooooooooooooooot... This snippet was very easy for me to get and exactly what i wanted.
|
|
|
|
|
The principle is exactly the same as Passing Values between Forms in .NET[^], but instead of accessing a property, you access a method instead.
Does this help?
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
Looks like accessing data across forms is the most popular question on the C# board.
You'd be a rich man by now if you got a penny everytime you replied with a link to that article
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
S. Senthil Kumar wrote: Looks like accessing data across forms is the most popular question on the C# board.
Why do you think I wrote the article? (Not for the money obviously, but so I could just link to it so I didn't have to repeat myself ad nauseum)
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
Hi,
I was looking for an easy interface between child and partent without creating MDI. I visited the code project article, where I found passing value from parent to child was easy, but child to parent was very tough. Then I found the code solution in MSDN to pass variable between forms. Unfortunately that was not working. So, I was thinking is there any easy snippet to pass value or call method from Child to parent without MDI ?
Thanks
Emran
|
|
|
|
|
emran834 wrote: So, I was thinking is there any easy snippet to pass value or call method from Child to parent without MDI ?
Yes, but it would make your application very tightly coupled. This would reduce the ability to modify the application in the future (in other words, it would make any modifications quite time consuming to make). The structure I use in the article is loosely coupled which helps you make changes in the future.
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
Hey, can anyone teach me how to create a custom progressbar control which can have multiple colors? For e.g. values 0-50 = green, 50-80=yellow and 80-100 = red.
Thank you.
|
|
|
|
|
Web or desktop development?
Do you really want to make it yourself? If not I would take a good progress bar from here (like this one[^]) and change its color depending on the current value.
|
|
|
|
|
it would be on a desktop environment, but what i want is, a progress bar with different colors. Meaning that it would look something like how u detect ur audio input levels, u know those indicators with green, yellow and red colors?
|
|
|
|
|
|
Thanks but that's not what I want, that only has a single color in the progressbar, what i need is to have more than one color in the same bar.
|
|
|
|
|
The source is available, why don't you take a look how the author has implemented the OnPaint method and modify it by yourself?
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
okie, thank you guys very much
really appreciate the help.
|
|
|
|
|
Hi.
I am looking for a control that works like "DataList" in ASP.NET to be used in a C# Windows Forms Application.
What is recommended?
Thanks.
|
|
|
|
|
I can type an IP address and receive Internet domain name and my workstation name however no other IPs of computers on our internal network will resolve to a thier machine name only to the same IP that is entered. What's up Microsoft????
I can say that before we switched over .NET 1.1 to 2.0 the Dns.Resolve(entry); would find a name for any IP, LAN or WAN.
Q. Any ideas??????????
[This is new .NET 2.0 method that replaced the former .Resolve method]
private void LookupIP(string entry)
{
try
{
IPHostEntry IP = Dns.GetHostEntry(entry);
txtBox2.Text = IP.HostName;
}
catch(Exception exception)
{
|
|
|
|
|
when i add a control to a form it adds to Location(0,0)
but if i have a menu on my form it adding it to Location(0,0) is under the menu so i need to offset Location(0,menuheight)
how to handle situation like this ?
i've been using this.ClientRectangle to set Location
|
|
|
|
|
I'm making a C# app that does alot of xpath queries, and I was having trouble with one. Here is the xml I am working with:
<?xml version="1.0" encoding="utf-8"?>
<reviewers>
<reviewer>
<name>Matti Latva-aho</name>
<email>asf@asf</email>
<country>Finland</country>
<affiliation>University of Oulu</affiliation>
<username>matla</username>
<password>19harava</password>
<interests>
<interest>Track II</interest>
<interest>Track IV</interest>
<interest>Track III</interest>
</interests>
<papers>
<id>1</id>
</papers>
</reviewer>
</reviewers>
My question is how can I get - using XmlNode.SelectNodes() - get all the "reviewer" nodes with "id" node that is equal to a number x. ???
Using the below expression I can get the papers node with the id that I specify, but I want the parent of papers, reviewer.
XmlNodeList reviewerNodes=docReviewers.SelectNodes("//reviewers/reviewer/papers[id='"+p.id+"']");
/\ |_ E X E GG
-- modified at 18:33 Saturday 11th February, 2006
|
|
|
|
|
How about:
/reviewers/reviewer[papers/id = '1']
|
|
|
|
|
Thanks, I also discovered
"//reviewers/reviewer/papers[id='"+p.id+"']/parent::*"
works too.
/\ |_ E X E GG
|
|
|
|
|
-<papers>
<id>1</id>
<id>2</id>
</papers>
I want to select an id based upon it's value..
What is an xpath expression to get an id=1 or 2???
I'm not sure how to get to the child elements id from papers by the id value.
/\ |_ E X E GG
|
|
|
|