Passing Data Between Forms

O

OG

I'm trying to learn C# 2008 on Microsoft's MSDN. Their walkthrough
example on passing data between forms at http://msdn.microsoft.com/en-us/library/ms171925.aspx
had this error in the C# version when I tried it:

'PassingDataBetweenForms.Form2' does not contain a definition for
'Form2_Load' and no extension method 'Form2_Load' accepting a first
argument of type 'PassingDataBetweenForms.Form2' could be found (are
you missing a using directive or an assembly reference?)

Can anyone help me clarity or correct the coding?
 
M

Morten Wennevik [C# MVP]

Hi OG,

There are two pieces of information missing in that tutorial.

The tutorial correctly tells you to replace Form2_Load with the LoadOrders
method, but Form2_Load is an event method referred to in the designer code.

If you double click the error line you should end up at the line below.
Comment it out or delete the line

//this.Load += new System.EventHandler(this.Form2_Load);

The reason for this is the Form2_Load method fills the datagrid with ALL
orders whereas you want to display only those for a selected customer. It
probably won't do much difference if you leave the Form2_Load method and just
add the LoadOrders method as the content of the grid will be replaced.

Also, the customersDataGridView_DoubleClick method you add last is an event
method as well, but it isn't connected to the DoubleClick event. To fix this
change Form1_Load in Form1.cs to the below (formatted for readability)

private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the
// 'northwindDataSet.Customers' table.
// You can move, or remove it, as needed.
this.customersTableAdapter.Fill(this.northwindDataSet.Customers);

// This line attaches the customersDataGridView_DoubleClick
// method to customersDataGridView's DoubleClick event
this.customersDataGridView.DoubleClick +=
new EventHandler(customersDataGridView_DoubleClick);
}
 
O

OG

Hi OG,

There are two pieces of information missing in that tutorial.

The tutorial correctly tells you to replace Form2_Load with the LoadOrders
method, but Form2_Load is an event method referred to in the designer code..

If you double click the error line you should end up at the line below.  
Comment it out or delete the line

//this.Load += new System.EventHandler(this.Form2_Load);

The reason for this is the Form2_Load method fills the datagrid with ALL
orders whereas you want to display only those for a selected customer.  It
probably won't do much difference if you leave the Form2_Load method and just
add the LoadOrders method as the content of the grid will be replaced.

Also, the customersDataGridView_DoubleClick method you add last is an event
method as well, but it isn't connected to the DoubleClick event.  To fixthis
change Form1_Load in Form1.cs to the below (formatted for readability)

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loadsdatainto the
            // 'northwindDataSet.Customers' table.
            // You can move, or remove it, as needed.
            this.customersTableAdapter.Fill(this.northwindDataSet.Customers);

            // This line attaches the customersDataGridView_DoubleClick
            // method to customersDataGridView's DoubleClick event
            this.customersDataGridView.DoubleClick +=
                new EventHandler(customersDataGridView_DoubleClick);
        }

--
Happy Coding!
Morten Wennevik [C# MVP]



OG said:
I'm trying to learn C# 2008 on Microsoft's MSDN. Their walkthrough
example onpassingdatabetweenformsathttp://msdn.microsoft.com/en-us/library/ms171925.aspx
had this error in the C# version when I tried it:
'PassingDataBetweenForms.Form2' does not contain a definition for
'Form2_Load' and no extension method 'Form2_Load' accepting a first
argument of type 'PassingDataBetweenForms.Form2' could be found (are
you missing a using directive or an assembly reference?)
Can anyone help me clarity or correct the coding?- Hide quoted text -

- Show quoted text -

Thank you very much!
Your coding corrects the problem and it now works.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top