Dynamic list retrieveOld forum URL: forums.lhotka.net/forums/t/8390.aspx
Calin posted on Thursday, January 21, 2010Hi,
Imagine a form with 3 comboboxes, each combo gets populated by a DataProvider. Now based on the selection on the first combo the elements in the next 2 might change.
As a specific example. The first combo is a list of institutions, the second combo is a list of available departments of a institution. When selecting a institution I need the second combo to bring only the departments specific to that institution.
Now the classic Instituion has a collection of deparments approach does not work because I have a bunch of institutions and many departments on each. What I need to do is when I select a institution the DataProvider of the deparments combo should go back and fetch the departments with the new institution id.
Is there a way to do this ?
Fintanv replied on Thursday, January 21, 2010I do this by having the lists (read only collections) exposed by a use case level root business object. The root object also has the properties required for the retrieval of the main business object (which is exposed as a child property of the root business object). The selection of a value from a combo will update the property in the business object. This will trigger the (re-)selection of dependant lists bound to the other combos. Since the changed list has changed, I get a property changed notification. Since I am using WPF this works very nicely as I get a re-binding of the combo.
Fele replied on Thursday, January 21, 2010I will refresh other combobox's each time user change selection:
CslaDataProvider factoriesProvider = this.Resources["Cbo1Data"] as CslaDataProvider;
factoriesProvider.FactoryMethod = "GetDataForCbo1";
CslaDataProvider factoriesProvider = this.Resources["Cbo2Data"] as CslaDataProvider;
factoriesProvider.FactoryMethod = "GetDataForCbo2";
Calin replied on Thursday, January 21, 2010Thanks for the reply Fele,
By looks of it this code sits in a event on the view, unfortunately I don't like this approach to much I am using wpf and MVVM and this does not really fall in this pattern.
It will really help if I could bind the FactoryParameters.
Fele replied on Thursday, January 21, 2010Calin,
If you figure it out let me know. I have exactly the same issue in Silverlight.
marthac replied on Monday, September 13, 2010
Did you ever figure out how to do this in Silverlight using the CslaDataProvider?
I have a CslaDataProvider defined for my grid data and a CslaDataProvider for each combo (NameValueLists)
For the first combo, I have a SelectionChanged event handler and in there I'm calling the factory method to load a second combo data using the selected value from the first.
It loads the second combo values just fine, but the grid data value bound to the combo is not displayed in it.
I have tried calling Rebind on the grid CslaDataProvider and it does cause the selection to be shown in the second combo, but it clears the selection in the first combo.
Can anyone explain how to do this?
RockfordLhotka replied on Monday, September 13, 2010
You might be hitting a timing issue, since all three data providers will do independent async server calls.
To avoid this, you might need to use the unit of work pattern and have one data provider make the server call. I don't remember if I enabled "chaining" of data providers, but I think I did - so you could have (basically) four providers:
- UOWProvider - gets all the data
- BusinessObjectProvider - binds its Data property to UOWProvider.Data.BusinessObject
- List1Provider - binds its Data property to UOWProvider.Data.List1
- List2Provider - binds its Data property to UOWProvider.Data.List2
I know this works with ViewModel<T>, and I think I made this scenario work with CslaDataProvider before I switched my attention to MVVM.
Calin replied on Thursday, January 21, 2010Thank you for your reply Fintanv,
Indeed at the moment this is the approach I use, but the down fall of this is that when I change the selection in the first combo there is a small freeze time because the application goes back and gets the entities to populate the other combos.
I prefered CslaDataProvider for it's IsAsyncronus = true and DataErrorHandler. Further more the nice waiting from PropertyStatus is also rendered unusefull in this scenario.
Copyright (c) Marimer LLC