Results 1 to 3 of 3

Thread: [RESOLVED] Passing Params to New Form

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Location
    Washington, DC
    Posts
    422

    Resolved [RESOLVED] Passing Params to New Form

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Passing Params to New Form

    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:
    Code:
    		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:
    Code:
            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;
    		}
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Location
    Washington, DC
    Posts
    422

    Re: Passing Params to New Form

    Thank you for the help.

    Issue resolved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width