• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

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".
0
Peter Allen
Asked:
Peter Allen
  • 4
  • 4
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
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
0
 
Peter AllenAuthor Commented:
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.
0
 
Éric MoreauSenior .Net ConsultantCommented:
the "solution 2" from my article will work with 2 datasets.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Peter AllenAuthor Commented:
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

0
 
Éric MoreauSenior .Net ConsultantCommented:
do you have manufacturer without printerseries?

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

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

http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.filter.aspx
0
 
Peter AllenAuthor Commented:
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.
0
 
Éric MoreauSenior .Net ConsultantCommented:
and both Manufacturer_Name and PrinterSeries_Name contains the same value (is has to be the foreign key between your 2 tables).
0
 
Peter AllenAuthor Commented:
I had to adjust the code slightly, but it worked.  Thank you
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now