Link to home
Start Free TrialLog in
Avatar of Peter Allen
Peter AllenFlag for United States of America

asked on

Two DataSets and Two ComboBoxes - Dependent

Experts,'

I have a situation where I have two ComboBoxes.  I defined a BindingSource for each.  ComboBox A has bsManufacturer (dsManufacturer = DataSource).  The field/DisplayMember is "Manufactuer_Name".  ComboBox B has bsProductSeries (dsProductSeries = DataSource).  The fiels DisplayMember is "ProductSeries_Name".

So both bs and ds have the fiels "Manufacturer_Name".  ComboBox A is the primary control.  ComboBox B is filtered based upon ComboBox A.  My problem is getting the Filter correct for ComboBox B.  Could you help me with this please?  Thank you.

I'm thinking that Filter for ComboBox B should be something like "Filter = Manufacturer_Name = ComboBoxA.Text".
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

can you get both datatable in the same dataset?

check http://emoreau.com/Entries/Articles/2007/01/Setting-a-masterdetail-relationship-between-two-ComboBox.aspx for a couple of ideas
Avatar of Peter Allen

ASKER

No because ComboBox A pulls up a list of Manufacturers out of the Assets database.  The Printer Series table is Stored in the Stock database, but they share the same Manufacturer field.  That is why I am using it (or want to anyway) to filter ComboBox B.

As a user defines different Product Series for different Printers not all Manufacturers will be used because some Manufacturers do not make Printers.

So when you open the Form to add a Model of a Printer you first select the Manufacturer, then the Printer Series you want associated to a partifular Model of Printer.
the "solution 2" from my article will work with 2 datasets.
emoreau,

OK.  I have the following code which appears to work, but when run produces the following error...  "The constraint cannot be enabled as not all values have corresponding parent values".  

This is telling me that I need to account for NULL relations and I'm trying to figure out where to piut that code.  Any ideas please?
dsPrinterSeries.Relations.Add("dtPrinterSeries", _
dtAssetManufacturer.Columns("Manufacturer_Name"), _
dtdtPrinterSeries.Columns("PrinterSeries_Name"))

Open in new window

do you have manufacturer without printerseries?

you better revert to solution 2 for which you don't need a relation
Try this

bsProductSeries.Filter = "Manufacturer_Name = '" & ComboBoxA.Text & "'"

http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.filter.aspx
emoreau,

The Manufacturer table will have ALL Manufacturers listed for the Asset database, but only those Manufacturers listed in the PrinterSeries table should appear.  The relation will not have a NULL for any Manufacturer.
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I had to adjust the code slightly, but it worked.  Thank you