4 Replies - 1905 Views - Last Post: 19 December 2009 - 04:57 AM Rate Topic: -----

#1 teyew  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-May 09

Pass data between form

Post icon  Posted 16 December 2009 - 03:04 PM

I meet some problem with how to pass data between form if the data is more than 1? any example for it? Thanks a lot
Is This A Good Question/Topic? 0
  • +

Replies To: Pass data between form

#2 chewie  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 28-May 08

Re: Pass data between form

Posted 16 December 2009 - 03:09 PM

http://www.codeproje...ween_forms.aspx
Was This Post Helpful? 0
  • +
  • -

#3 MentalFloss  Icon User is offline

  • .
  • member icon

Reputation: 577
  • View blog
  • Posts: 1,500
  • Joined: 02-September 09

Re: Pass data between form

Posted 16 December 2009 - 03:15 PM

Create a class that contains your data to be passed then pass it in constructor is one way:

public class UserSelections
{
	public string SomeField { get; set; }
	public string SomeOtherField { get; set; }
}

public class SecondForm : Form
{
	private UserSelections userSelections;

	public SecondForm(UserSelections selection)
	{
		userSelections = selection;
	}
}

public class MainForm : Form
{
	public MainForm()
	{
		// Init stuff here.
	}

	private void ShowSecondForm()
	{
		UserSelections selections = new UserSelections();
		selections.SomeField = someTextBox.Text;
		selections.SomeOtherField = someOtherTextBox.Text;

		SecondForm s = new SecondForm(selections);
		s.Show();
	}
}



Now second form will have the knowledge that first form has and you have passed more than one value into it. In fact, you can expand your UserSelections class to have whatever you want and your SecondForm will have that info.

Maybe this is what you wanted.
Was This Post Helpful? 1

#4 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1533
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: Pass data between form

Posted 16 December 2009 - 06:52 PM

I created a tutorial on this.

http://www.dreaminco...wtopic75208.htm
Was This Post Helpful? 0
  • +
  • -

#5 karimi  Icon User is offline

  • Banned
  • member icon

Reputation: -9
  • View blog
  • Posts: 104
  • Joined: 29-May 09

Re: Pass data between form

Posted 19 December 2009 - 04:57 AM

Using instanced class is not a goode idea to share data between forms. Why r u intended to increase burden on the memory.
Use static class as

public static class MyData
{
 public static  string SomeData;
}
///
anywhere in ur application u can access or assign this datamember of class as

MyDate.SomeData="--some--data"; // without instanciatine
// similarly
strimg val=MyData.SomeData; 


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1