I have what I think should be a simple question regarding a bound combo box.
My first table is Dealers:
DealerID - primary key
DealerName
BillToLocation
My second table is Locations:
LocationID - primary key
LocationDescription
DealerID - DealerID of the dealer this location belongs to
I want a bound combo box that when on a dealer record it displays the
LocationDescription for the dealer record's BillToLocation. But I want the
user to be able to change the BillToLocation to one of the dealers locations
in the Locations table.
At this point I have a combo box that shows only that Dealer's locations in
the drop down list, will update the BillToLocation when it's selected and
saved, but unfortunately it doesn't display correctly as I navigate through
the records using bmDealers.Position++ or bmDealers.Position--;
Interestingly enough, if I load a particular dealer record, it displays the
correct LocationDescription, but if navigate away and then back, it gets out
of sync.
Could someone give me some guidance as to what I'm doing wrong? Thank you.
Here is the binding code:
dsCoinTableAdapters.DealersTableAdapter daDealers = new
dsCoinTableAdapters.DealersTableAdapter();
dtDealers = ds.Dealers;
daDealers.Fill(dtDealers);
dsCoinTableAdapters.LocationsTableAdapter daLocations = new
dsCoinTableAdapters.LocationsTableAdapter();
dtLocations = ds.Locations;
daLocations.Fill(dtLocations);
DataColumn pdc = dtDealers.DealerIDColumn;
DataColumn cdc = dtLocations.DealerIDColumn;
DataRelation dr = new DataRelation("DealerToLocations", pdc, cdc);
ds.Relations.Add(dr);
bmDealers = this.BindingContext[ds, "Dealers"];
drDealer = dtDealers.FindByDealerID(nDealerID);
bmDealers.Position = dtDealers.Rows.IndexOf(drDealer);
txtDealerID.DataBindings.Add(new Binding("Text", ds,
"Dealers.DealerID"));
txtDealerName.DataBindings.Add(new Binding("Text", ds,
"Dealers.DealerName"));
cboBillToLocation.DataSource = ds;
cboBillToLocation.DisplayMember =
"Dealers.DealerToLocations.LocationDescription ";
cboBillToLocation.ValueMember =
"Dealers.DealerToLocations.LocationID";
cboBillToLocation.DataBindings.Add(new Binding("SelectedValue",
ds, "Dealers.BillToLocation"));