views:

135

answers:

1

I have a simple SQLite database I use to track invoices. I recently decided to write an application for it as an excuse to learn LINQ. I found other questions that address this issue, but none of the solutions worked for me.

Using the O/RM designer, I modeled my database similar to the following (simplified):

+------------+           +----------+
|  Invoice   |           | Customer |
+------------+           +----------+
| ID         |      +----| ID       |
| CustomerID |<-----+    | Name     |
+------------+           +----------+

This works great for binding the invoices table to a list and seeing a list of customers, but I'm not quite getting how to bind the table of customers to a ComboBox while showing the Customer for the invoice.

Here's the code that sets up the binding:

InvoiceList.DataSource = _db.Invoices;  // InvoiceList is ListBox
CustomerBox.DataSource = _db.Customers;  // CustomerBox is ComboBox
CustomerBox.DataBindings.Add("SelectedItem", InvoiceList.DataSource, "Customer");

In this case, _db is the DataContext generated by the O/RM.

As I select different items in the invoice list, the customer box doesn't seem to show any changes I've made. Any pointers how to correct this? Is there a better way to setup this binding?

+1  A: 

Have you looked at using a BindingContext?

And here's a slightly less opaque description :)

flesh
I played around with it and that seemed to help. Somehow, I went back to my original code and it's working now. That bugs me... Thanks for the help.
jheddings