New Posts New Posts RSS Feed: Problems with nested proprerty and databinding
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Problems with nested proprerty and databinding

 Post Reply Post Reply
Author
Dominique View Drop Down
Groupie
Groupie
Avatar

Joined: 28-Jun-2007
Location: Norway
Posts: 44
Post Options Post Options   Quote Dominique Quote  Post ReplyReply Direct Link To This Post Topic: Problems with nested proprerty and databinding
    Posted: 05-Jul-2007 at 9:54am
Hi,

I'm still strugling to databind my combos. It did worked earlier today but not any more now as I should go home.

* I have a structure looking like:
Person -> City -> Country
* I have the following UI:
the details of a persons are presented with loose controls
a datagridview presents a list of person with a summary including city/coutry as readonly textboxes
They share the same bindingSource object

* would it be possible to do the following with databinding:

1> user updates a Person entity in the details view
the user chooses a country -> update the list of cities
the user choose a city -> update Person.city

2> user navigates through the person list by selecting a row in the datagridview
the combos display the right country/city <- ok

3> the model changes (from another screen)
the combos display the right country/city   <- ok
the readonly textboxes in the gridview are updated <- almost (I need to listen to the listChanged event and tell the grid to refresh itself, I buy any better way here :-)

I can handle the combos manually (done that on one screen) but it would be sweet to do it with databinding

Dominique

Edited by Dominique - 05-Jul-2007 at 9:58am
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 06-Jul-2007 at 2:23pm

Here is something that I posted on the IdeaBlade NewsGroup last winter 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 lastSalesOrder

 

 

Back to Top
Dominique View Drop Down
Groupie
Groupie
Avatar

Joined: 28-Jun-2007
Location: Norway
Posts: 44
Post Options Post Options   Quote Dominique Quote  Post ReplyReply Direct Link To This Post Posted: 07-Jul-2007 at 1:58pm
Hi,
I found your post on the news group just before checking here :-). Any way, thanks fo your attention.
I see how It would work if "Each SalesOrder has an asssociated Province and City". In my case it's more "Each SalesOrder might have an asssociated City and Each City has an asssociated Province".

i.e. SalesOrder.City and SalesOrder.City.Province, and City can be the NullEntity.
This last point leads to the city being the nullentity each time the province is changed (and might also give some "updating the nullentity" messages, but I can't remember for sure). It could work by selecting the first city wich is not the nullentity in the refreshed list, It would be a hack but I guess it would get the work done.

I actually gave up using databinding for the combos and handle them "manually".

Dominique
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 09-Jul-2007 at 8:56am
Dominique,
 
If you look at the intermediate tutorial "264. - Working with ComboBoxes", you'll find a good example of using the Null Entity with a ComboBox.  In this tutorial, the Null Entity is used as one of the possible choices for Manager (since not every Employee may have a Manager - e.g., president of the company, Employee whose manager just left the company).  Note that in this tutorial, the Null Entity is added to the EntityList for Managers:
 
 mManagers = mPM.GetEntities<Employee>();
 mManagers.Add(mPM.GetNullEntity<Employee>());
 mManagerSource.DataSource = mManagers;
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down