Results 1 to 3 of 3

Thread: passing variables from one form to another [* Resolved *]

Threaded View

  1. #1

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

    passing variables from one form to another [* Resolved *]

    Hello,

    I have my mdi form. One of the child forms displays a datagrid of employee salaries.

    On the mdi form l have a button called update. I want to pass the Employee ID number from the grid and display it in another form.

    This is what l have done so far, but does not work.
    In the salaries form (datagrid form) i have this code.
    Code:
                                    /****************************
                                    Set a variable and store the ID number in this value when the user clicks the grid row
                                    ****************************/
    		private string employeeNumber;
    		employeeNumber = grdSalaries[grdSalaries.CurrentRowIndex,0];
    
                                    /******************************************************
    		 *For sending this employeenumber to the update form
    		 * to update the correct employee details
    		 * ****************************************************/
    		public string getEmployeeNumber
    		{
    			get
    			{
    				return employeeNumber;
    			}
    			set
    			{
    				value = employeeNumber;
    			}
    		}

    In the update form l have this code in the form load.
    employeeNumber = parent.getEmployeeNumber;


    I have declared these above the constructor
    private string employeeNumber;
    frmSalaries parent;

    My constructor is listed below

    Code:
    public frmUpdateEmployee(frmSalaries form)
    		{
    			//
    			// Required for Windows Form Designer support
    			//
    			InitializeComponent();
    
    			//
    			// TODO: Add any constructor code after InitializeComponent call
    			//
    			parent = form;
    		}
    The error message is below
    An unhandled exception of type 'System.NullReferenceException' occurred in payrole.exe

    Additional information: Object reference not set to an instance of an object.

    The way the program works is the main control buttons are displayed in the mdi, when you click on show salaries it displays the form with the grid. The user will click once on the grid and then click on the update button on the mdi form. This will then display another form which is passed the ID number so l know who i have to update.

    Many thanks in advance,

    Steve
    Last edited by steve_rm; Jan 30th, 2005 at 05:45 AM.
    steve

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