Link forms (newbie)

J

JP

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.
 
J

JP

Thanks for the suggestions. I'm at the step-by-step learning stage. Could you
be kind enough to show the coding?
 
J

JP

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.
 
J

JP

Peter Duniho said:
What is your expectation of the behavior of the frmOrder instance when the
frmCustomer instance used to open it is closed? Can the single
frmCustomer instance change the customer it's displaying? Or is it in
turn opened from a form showing a list of customers, always showing the
same customer?

The answer to that is important with respect to how best to implement what
you're asking, because if the opened order form can only ever show one
customer's data, then you might as well just pass the CustomerID to the
frmOrder constructor. In that case, I would seriously consider making the
form modal also (i.e. use ShowDialog() instead of Show()). Otherwise, the
UI can get complicated, either with getting the forms out of synch or
having more than one frmOrder opened at a time without a clear indication
as to which other form it's associated with.

Alternatively, if the user can change the currently displayed user in the
frmCustomer form while the frmOrder is being displayed, then you'll want
to use a mechanism that allows for changing the filtering criteria while
the form is still open.

As for posting code, I'm happy to post some basic skeletal code (i.e.
leaving a lot of stuff out, including the specifics of updating the
DataGridView). But I'd like to know first the exact mechanism you expect
to use (based on the answers to the above).

I'm just going for the basic and the uncomplicated. The 2 forms, frmCustomer
& frmOrder, are only in sync when frmOrder is opened from frmCustomer using
CustomerID as the filter.

Form frmCustomer is the starting form of the application and is not opened
by any other form. The list of customers are in a comboBox control within
form frmCustomer which allows the user the only occasion to pick a particular
customer by CustomerName. This comboBox, cboCustomer, has CustomerName as
its "Display Member" and CustomerID as its "Value Member" properties.

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.
 

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