Navigation using linked combo box and syncronization with a list box

G

George Gîta

I want to do the following:
- have a combo box linked to the Customers table
- have a list box linked to the Orders table

When I select a Customer from the combo, the list box will display all the
Orders from that Customer.

So far I managed to make the connection to the database and 2 sql data
adapters, one with data from Customers, other from Orders.
After that I buit a DataSet from that 2 sql data adapters, having 2 tables
"Customers" and "Orders".

And now I'm stuck.
How can I syncronize the combo with the list box ? Is there a posibility
like RowFilter in DataGrid? Or maybe using BindingContext ?
How?

Thanks in advance.
 
B

Bart Mermuys

Hi,

George Gîta said:
I want to do the following:
- have a combo box linked to the Customers table
- have a list box linked to the Orders table

When I select a Customer from the combo, the list box will display all the
Orders from that Customer.

So far I managed to make the connection to the database and 2 sql data
adapters, one with data from Customers, other from Orders.
After that I buit a DataSet from that 2 sql data adapters, having 2 tables
"Customers" and "Orders".

Ok, so you should verify if you already have a DataRelation inside the
DataSet that links Customers and Orders. You can do this using the DataSet
Schema Designer or from code. Let's assume you have a relation named
"Customers_Orders", then you can do the binding like:

// bind to table via dataset
CustomersComboBox.DataSource = ds;
CustomersComboBox.DisplayMember = "Customers.Name";

// bind to table+relation via dataset
OrdersListBox.DataSource = ds:
OrdersListBox.DisplayMember = "Customers.Customers_Orders.OrderID";

This way the OrderListBox will only show records belonging to the current
Customer in the CustomersComboBox. A ListBox can only show one field, so i
used OrderID, but it can be any field, though i can imagine displaying more
then one field for orders, maybe you should consider a DataGrid:

// bind to table+relation via dataset
OrdersDataGrid.DataSource = ds;
OrdersDataGrid.DataMember = "Customers.Customers_Orders";


HTH,
Greetings
 

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