Re: Navigation using linked combo box and syncronization with a list box by Bart
Bart
Thu Dec 01 06:05:19 CST 2005
Hi,
"George Gîta" <george@vital-heyl.com> wrote in message
news:Oci%232ua9FHA.1188@TK2MSFTNGP12.phx.gbl...
>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
>
> 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.
>
>
>