PDA

Click to See Complete Forum and Search --> : [RESOLVED] Passing Params to New Form


fllewis
Dec 14th, 2005, 07:29 PM
I'm starting my first C# project and have a simple question:

I have a listview that a user can select items from. I am passing a value from the item selected to a new form. How can I pass the params from one form to another. I need to use a key from one form to open data in another, but I can't figure out how to get that value from one form to another.

Thanks,

FLL

jmcilhinney
Dec 14th, 2005, 11:04 PM
A form is nothing special. It is an object just like any other. How would you normally pass data to an object that you just created? You would pass a value as an argument to the constructor, which is the most likely choice in your case, or else you would either set a property or call a method and pass an argument. Like I said, the best option in your case would be to use the constructor. You should either edit the existing constructor or write a new one that accepts an argument of the appropriate type and assigns that value to a private member variable. The default constructor would look something like this: public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}You would need to change that to something like this: private int recordID;

public Form1(int recordID)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
this.recordID = recordID;
}

fllewis
Dec 15th, 2005, 07:37 PM
Thank you for the help.

Issue resolved.