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?