New Posts New Posts RSS Feed: How to populate a second combobox which depends on selection in first combobox
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

How to populate a second combobox which depends on selection in first combobox

 Post Reply Post Reply
Author
Customer View Drop Down
Senior Member
Senior Member
Avatar
User Submitted Questions to Support

Joined: 30-May-2007
Location: United States
Posts: 260
Post Options Post Options   Quote Customer Quote  Post ReplyReply Direct Link To This Post Topic: How to populate a second combobox which depends on selection in first combobox
    Posted: 16-Jul-2007 at 3:17pm

I have created a window for our sales orders that looks like the following screen shot.  Please note two things:  1)  The selected customer has a range of addresses to choose from (2 in the case displayed); 2)  The selected customer has a range of contacts to choose from (1 in the case displayed).

 

The next screen shot shows the address list available...it reflects ALL addresses in the system, not just the addresses specific to the customer.  Also, the same result occurs with the contacts.  The correct address and contact are selected; however, the lists should be limited to only the addresses and contacts pertinent to the customer.

 

I am at a loss to figure out how to do this.  Here is the code that I am using to populate the window:

  

The initial binding of the lists to the combo boxes seems to be working fine, even with the null object inserted and the list sorted.  The limiting of the list is the tricky part.  I have attempted to contact support a couple of times...I believe I had spoken with Paul.  He suggested to utilize the bindingsource objects.  This is what I am trying to do.  I have gotten rather far with the objects, but just cannot seem to get around this corner. 

 

What is the trick to doing this with your business objects?  I will continue working on the problem.  I am close, I believe. 

 

A second, related issued is the changing of the customer.  If I change the customer, I want to updates several things: customer ID, default commission, addresses and default bill-to and ship-to, contacts and default carrier (based on default ship-to).  What event should I focus on in order to make this happen?  If I use the selectedindexchanged event, the code fires whenever I change sales orders.  That is not good.  I only want the event to fire when I change the customer on the currently selected sales order.  I cannot imagine that this is a very difficult thing.  I have gone through all of the videos and the documentation.  It just isn't getting me past these humps.

 

Hope to hear from you soon.

Back to Top
IdeaBlade View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 30-May-2007
Location: United States
Posts: 353
Post Options Post Options   Quote IdeaBlade Quote  Post ReplyReply Direct Link To This Post Posted: 16-Jul-2007 at 3:19pm
Here is something that I posted on the IdeaBlade NewsGroup on how to populate ComboBoxes when the list of entities in the ComboBox changes as the result of the currently selected item in some other ComboBox.

 

A Customer asked: 

 On my windows form I have a drop down with our country's Provinces and
i have a drop down of cities, the cities have a relationship in the
Database with the Provinces, I'm wondering now how can I get the
cities to only show those linked to a specific province when this one
is selected?

I replied:

I will show how to do this with a form that edits SalesOrders.  Each SalesOrder has an asssociated Province and City.  As you stop on a particular SalesOrder, the ComboBox for Cities will show you only cities for that Province.  If you select a different province from the Province ComboBox, the ComboBox for Cities will immediately display all of the cities from the new province. 

Here is how to do this:

(1)    Using the designer for the ControlBindingManager, create a ComboBox for SalesOrder.Province.   Populate the EntityList for this ComboBox with the list of all Provinces. 

(2)    Using the designer for the ControlBindingManager, create a ComboBox for SalesOrder.Cities.   Populate the EntityList for this ComboBox, not with all of the Cities in the Citiy Table, but rather with the list of all Cities that are in the currently selected Province..

(3)    Create an event handler for the BindingSource.CurrentChanged of SalesOrder.  Record the identity of the current SalesOrder (i.e., lastSalesOrder) 

(4)    Create an event handler for the BindingSource.CurrentChanged of Province.  This event handler needs to populate the EntityList for Cities when the CurrencyManager changes its position.  There are two cases.  The first case is when we are moving from SalesOrder to SalesOrder.  This requires repopulating the EntityList with Province.Cities from the new Province in the new SalesOrder.  The second case is when when we are changing the Province in the current SalesOrder.  This requires repopulating the EntityList with Province.Cities from the newly selected Province in the ComboBox.  In addition, we must choose a new SalesOrder.City value.  We don't know which City to pick, so we just pick the first one.  We decide whether we are in case 1 or case 2 by comparing the current SalesOrder to lastSalesOrd

 

 

 

 

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down