Groups | Blog | Home
all groups > dotnet ado.net > november 2005 >

dotnet ado.net : Navigation using linked combo box and syncronization with a list box


George Gîta
11/30/2005 2:46:24 PM
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.


Bart Mermuys
12/1/2005 1:05:19 PM
Hi,

[quoted text, click to view]

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


[quoted text, click to view]

AddThis Social Bookmark Button