471,334 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,334 software developers and data experts.

Link forms (newbie)

I am beginning C# programming and am trying to open frmOrders from a button
in frmCustomer (in Northwind database) with CustomerID as the link between
the two forms. What is the easiest and quickest way to do this? I'm stuck at:

private void btnOrders_Click(object sender, EventArgs e)
{
Form newForm = new frmOrders();

newForm.Show();
}

not able to figure out how to filter frmOrders to only show the focussed
CustomerID in frmCustomer.
Jun 27 '08 #1
4 1542
On Sun, 27 Apr 2008 08:33:00 -0700, JP <JP@discussions.microsoft.com
wrote:
I am beginning C# programming and am trying to open frmOrders from a
button
in frmCustomer (in Northwind database) with CustomerID as the link
between
the two forms. What is the easiest and quickest way to do this? I'm
stuck at:

private void btnOrders_Click(object sender, EventArgs e)
{
Form newForm = new frmOrders();

newForm.Show();
}

not able to figure out how to filter frmOrders to only show the focussed
CustomerID in frmCustomer.
It's hard to say without knowing how you've structured the code in each
form. However, if the "frmOrders" class is to take as a filter a
"CustomerID", then you will need a couple of things:

* Some API in the frmOrder class that allows the setting of the filter
(seeing as how the form isn't modal, I suspect simply passing the value to
the constructor isn't sufficient...you probably want a property and/or
method that allows you to specify a new CustomerID value as the user
selection changes in the other form, as well as possibly allowing for
clearing the filtering altogether, if that's possible)

* The frmCustomer class will need to save the reference to the form
it's created and shown, so that as the user selection in the frmCustomer
form changes, it can then call the frmOrder API (see above) with the
appropriate CustomerID value to change the filtering. So rather than
assigning the new form instance to a local variable in your Click event
handler, you'll want a class instance member to which you can assign the
instance reference, so that you can get it later when the user changes the
selected customer.

Pete
Jun 27 '08 #2
Thanks for the suggestions. I'm at the step-by-step learning stage. Could you
be kind enough to show the coding?

"Peter Duniho" wrote:
On Sun, 27 Apr 2008 08:33:00 -0700, JP <JP@discussions.microsoft.com>
wrote:
I am beginning C# programming and am trying to open frmOrders from a
button
in frmCustomer (in Northwind database) with CustomerID as the link
between
the two forms. What is the easiest and quickest way to do this? I'm
stuck at:

private void btnOrders_Click(object sender, EventArgs e)
{
Form newForm = new frmOrders();

newForm.Show();
}

not able to figure out how to filter frmOrders to only show the focussed
CustomerID in frmCustomer.

It's hard to say without knowing how you've structured the code in each
form. However, if the "frmOrders" class is to take as a filter a
"CustomerID", then you will need a couple of things:

* Some API in the frmOrder class that allows the setting of the filter
(seeing as how the form isn't modal, I suspect simply passing the value to
the constructor isn't sufficient...you probably want a property and/or
method that allows you to specify a new CustomerID value as the user
selection changes in the other form, as well as possibly allowing for
clearing the filtering altogether, if that's possible)

* The frmCustomer class will need to save the reference to the form
it's created and shown, so that as the user selection in the frmCustomer
form changes, it can then call the frmOrder API (see above) with the
appropriate CustomerID value to change the filtering. So rather than
assigning the new form instance to a local variable in your Click event
handler, you'll want a class instance member to which you can assign the
instance reference, so that you can get it later when the user changes the
selected customer.

Pete
Jun 27 '08 #3
frmCustomer is a simple form showing information of one customer. It has a
comboBox to search for a customer. It has a button, btnOrders, which opens
the form frmOrders. frmOrders has one dataGridView showing the Orders table.
Customer table (represented in frmCustomer) is related to Orders table
(represented in frmOrders) in a one-to-many relationship.

At frmCustomer, when a particular customer is selected, I would like to be
able to see only all of that particular customer's Orders in the frmOrder's
dataGridView when I open frmOrder.

"Peter Duniho" wrote:
On Sun, 27 Apr 2008 08:33:00 -0700, JP <JP@discussions.microsoft.com>
wrote:
I am beginning C# programming and am trying to open frmOrders from a
button
in frmCustomer (in Northwind database) with CustomerID as the link
between
the two forms. What is the easiest and quickest way to do this? I'm
stuck at:

private void btnOrders_Click(object sender, EventArgs e)
{
Form newForm = new frmOrders();

newForm.Show();
}

not able to figure out how to filter frmOrders to only show the focussed
CustomerID in frmCustomer.

It's hard to say without knowing how you've structured the code in each
form. However, if the "frmOrders" class is to take as a filter a
"CustomerID", then you will need a couple of things:

* Some API in the frmOrder class that allows the setting of the filter
(seeing as how the form isn't modal, I suspect simply passing the value to
the constructor isn't sufficient...you probably want a property and/or
method that allows you to specify a new CustomerID value as the user
selection changes in the other form, as well as possibly allowing for
clearing the filtering altogether, if that's possible)

* The frmCustomer class will need to save the reference to the form
it's created and shown, so that as the user selection in the frmCustomer
form changes, it can then call the frmOrder API (see above) with the
appropriate CustomerID value to change the filtering. So rather than
assigning the new form instance to a local variable in your Click event
handler, you'll want a class instance member to which you can assign the
instance reference, so that you can get it later when the user changes the
selected customer.

Pete
Jun 27 '08 #4
On Mon, 28 Apr 2008 02:20:01 -0700, JP <JP@discussions.microsoft.com
wrote:
[...]
Passing the CustomerID from frmCustomer to the frmOrder constructer
sounds
like the way to go. What's the coding to do this? Just the basic skeletal
code will do. Thanks again.
class frmOrder
{
public frmOrder(CustomerID id)
{
// use "id" to prepare filtering as appropriate
}
}

Then when creating the form:

frmOrder form = new frmOrder(currentID);

where the variable "currentID" is whatever the current customer ID is (you
may find that you can just get this directly from the ComboBox control,
depending on your exact implementation).

For what it's worth, if the description "pass the CustomerID to the
frmOrder constructor" isn't sufficient for you to understand that the
above is what I mean, you may want to review your basic OOP techniques
before proceeeding. That wasn't exactly an esoteric technique I was
describing. :)

Pete
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Steve McLellan | last post: by
2 posts views Thread by Mr Newbie | last post: by
2 posts views Thread by Pink | last post: by
7 posts views Thread by AdeelAlvi | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.