Results 1 to 4 of 4

Thread: passing a variable value to another form [* Resovled *]

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    passing a variable value to another form [* Resovled *]

    Hello,

    I have a form with a variable. I want to be able to send this variable to another form.

    Example: i have a customer form and want to send the customer number to the update customer form. So when l click update customer the update customer form will receive the customer number from the customer form.

    Hope you understand this.

    Many thanks in advance,

    Steve
    Last edited by steve_rm; Oct 24th, 2004 at 10:40 PM.
    steve

  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099
    I think smething like this has been asked before, and that you need to pass a reference of the first form, to the second in the constructor, and then get the variable from the reference of the passed form. This would let you get and set the variable. Hope it helps

  3. #3
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Yes this question has bee asked before. Do a search and you should find something.

  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Create a public variable in the EditCustomer form that holds the customer id, something like this:

    public int CustomerID;



    Then, when you call this form from the main form, you will do something like this:
    EditCustomer frm = new EditCustomer();
    frm.CustomerID = 55;
    frm.ShowDialog();



    OR, you can make it as part of the constructor if the form will never operate without a customerid.....

    private int _customerID;
    public void EditCustomer(int customerID)
    {
    _customerID = customerID;
    }



    So when you go to create that form, you have to pass a customerid to it:
    EditCustomer frm = new EditCustomer(55);
    frm.ShowDialog();

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