p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > C# and C > C# 1.0 > C#
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 17th, 2008, 08:17 AM
Authorized User
 
Join Date: Feb 2008
Location: Vadodara, Gjarat, India.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing variables from 1 form to another.

hi Friends,
I want to know how to pass variables from one form to another.

Thank You in advance.
Any help is welcomed

JAININ
__________________
JAININ
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old February 17th, 2008, 06:15 PM
samjudson's Avatar
Friend of Wrox
Points: 4,336, Level: 27
Points: 4,336, Level: 27 Points: 4,336, Level: 27 Points: 4,336, Level: 27
Activity: 40%
Activity: 40% Activity: 40% Activity: 40%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 1,340
Thanks: 0
Thanked 26 Times in 26 Posts
Default

The best way is to define a public property on one form:

public string TheProperty
{
  get { return _myProperty; }
}

Then you can call it from the other form, provided you have a reference to the other form:

MyForm form = (MyForm)formReference;
Console.WriteLine(form.TheProperty);

If this doesn't help then you'll have to be more specific in your requirements.


/- Sam Judson : Wrox Technical Editor -/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old February 18th, 2008, 04:32 AM
Authorized User
 
Join Date: Feb 2008
Location: Vadodara, Gjarat, India.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think I got it. Thank u for your help.

JAININ
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old February 18th, 2008, 07:45 AM
Authorized User
 
Join Date: Feb 2008
Location: Vadodara, Gjarat, India.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I m not getting it,
Can you help me?
Actually i have an Mdi form and from it different form opens,
So i want that only 1 instance of any form is open at a given time.For that I m using a boolean variable in Mdi form. Now i want to access that boolean variable in another form which is a child form of Mdi form.
Can you solve my problem?

Thank You

JAININ
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old February 18th, 2008, 08:00 AM
samjudson's Avatar
Friend of Wrox
Points: 4,336, Level: 27
Points: 4,336, Level: 27 Points: 4,336, Level: 27 Points: 4,336, Level: 27
Activity: 40%
Activity: 40% Activity: 40% Activity: 40%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 1,340
Thanks: 0
Thanked 26 Times in 26 Posts
Default

Inside your MdiParent you will have a property, something like this:

public bool IsFormOpen
{
  get { return isFormOpenVariable; }
}

In your child you will do the following:

MyMdiParent parent = (MyMdiParent)this.MdiParent;
if( !parent.IsFormOpen )
{
  // whatever
}


/- Sam Judson : Wrox Technical Editor -/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old February 18th, 2008, 08:29 AM
Authorized User
 
Join Date: Feb 2008
Location: Vadodara, Gjarat, India.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I m still not getting it,
I want to change the value of the boolean variable in the childform and return that changed value to the MdiParent form when the child form closes,
but i get the following error.

Error 1 Property or indexer 'WindowsApplication1.MDIopeningpage.frmload' cannot be assigned to -- it is read only

Thank You.

JAININ
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #7 (permalink)  
Old February 18th, 2008, 08:38 AM
samjudson's Avatar
Friend of Wrox
Points: 4,336, Level: 27
Points: 4,336, Level: 27 Points: 4,336, Level: 27 Points: 4,336, Level: 27
Activity: 40%
Activity: 40% Activity: 40% Activity: 40%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 1,340
Thanks: 0
Thanked 26 Times in 26 Posts
Default

Right, you didn't say you wanted to 'change' the value, just 'access' it, so what I wrote above is a read only property.

public bool MyProperty
{
  get
  {
    return true;
  }
  set
  {
    // do something with 'value' here.
    Console.WriteLine(value);
  }
}

/- Sam Judson : Wrox Technical Editor -/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #8 (permalink)  
Old February 18th, 2008, 09:02 AM
Authorized User
 
Join Date: Feb 2008
Location: Vadodara, Gjarat, India.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I m still not getting it.

I want to change the value of the boolean variable of the Mdi form on the child form and return the changed value of the boolean variable back to the Mdi form.

Thank You for helping me
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #9 (permalink)  
Old February 18th, 2008, 09:39 AM
samjudson's Avatar
Friend of Wrox
Points: 4,336, Level: 27
Points: 4,336, Level: 27 Points: 4,336, Level: 27 Points: 4,336, Level: 27
Activity: 40%
Activity: 40% Activity: 40% Activity: 40%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 1,340
Thanks: 0
Thanked 26 Times in 26 Posts
Default

I'm not sure what you are having trouble with. My previous example above shows you how to write a property setter, so you can write the the property - you then store the 'value' in whatever internal variable you want to.

/- Sam Judson : Wrox Technical Editor -/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #10 (permalink)  
Old February 18th, 2008, 06:38 PM
Authorized User
 
Join Date: Feb 2008
Location: Vadodara, Gjarat, India.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The trouble is:: I have a MDI parent form and a child form for Suppplier details. Ok. Now when i first open the supplier form it opens normally and when I try yo open it again at that time it says that the form is already open.
For this i have used a boolean variable whose value is get to true once the form is opened. and that boolean variable is declared in Mdi Parent form. So now i want that when i close the Supplier form the boolean variable value should again be false.

But when I close the supplier form and try to open it again at that time also I get the message that your form is already opened. i.e.the value of the boolean variable is true only.

I want to get rid of this problem

Thank you in advance.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Variables CMOS Classic ASP Basics 2 January 22nd, 2006 07:38 PM
Passing variables karlirvin Beginning PHP 3 December 9th, 2005 04:37 PM
passing variables. ashokparchuri ASP.NET 1.1 4 March 18th, 2005 05:36 AM
Passing variables acko ASP.NET 1.x and 2.0 Application Design 1 December 23rd, 2003 09:40 AM
Passing variables jesseleon Access VBA 4 October 24th, 2003 02:45 PM



All times are GMT -4. The time now is 06:30 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc