BindingSource in State and Design time bindings

Topics: CAB & Smart Client Software Factory
Oct 26, 2005 at 9:47 AM
originally posted by: krijn

I've asked this question before but .. no answers. Hoping for some new idea's :

1. Is it a good idea to place BindingSource objects in state (through workitem) ?
2. I want to databind controls directly to state ex. textbox1.DataBindings.Add("Text",State("Customers"),"Name")
where State("Customers") equals a BindingSource object
3. Manage above without losing the new visual studio features (show datasources=>drag&drop columns and tables)

How does everybody handle this ? Typing DataBinding statements ? Custom Designers ? Continuous merge between state data and UI datasets ?
Oct 30, 2005 at 2:39 AM
originally posted by: krijn

I'm not giving up already

Here's my CAB story in (very) short :

1. WorkItem.Run loads entier needed dataset (Service.LoadOrder(orderID)
2. WorkItem.Run creates BindingSource objects for each needed DataTable and DataRelation
3. Views are created with multiple smartparts
4. smartParts connect there controls (DataBindings) to BindingSource State objects (I now remove all databindings on the smartpart and place new databindings directly to state (DataBindings.Add(Orders,"OrderID")
where Orders is : <State("Orders")> '= BindingSource object
5. Each smartpart loads static data through Controller
6. Each smartpart handles own DataTable actions (AddNew,Remove, Next, Previous, First, Last, ..)
Remark : By DataBinding 'magic' the Next or other BindingSource commands navigates all other smartparts to there correspondent data (through datarelation binding)

What's your CAB story ?
Nov 1, 2005 at 7:34 AM
originally posted by: wj77526

Can you show the detail code for us.

Thank you in advance.
Nov 2, 2005 at 5:05 AM
originally posted by: DLorenz

Well, we bind to objects that expose properties. In the above WorkItem, we put the object into the State. Then we put it in the child workitem's state. We add a BindingSource control to all of the SmartParts that will be doing binding and bind the appropriate fields. Finally in the code-behind of the SmartPart, we pull the object out of state and add it to the bindingsource control, binding the object to the appropriate controls. Then whenever you make changes on the SmartPart, those changes will be reflected in the WorkItem's state, too.
Nov 2, 2005 at 11:58 AM
originally posted by: Darrenarbell

That is exactly as I do it. I have one small problem though, our objects(Data transfer Objects) have been generated from a web service. On the server side these contain List<T> of associated objects. However, the wsdl generates these as arrays of type T, which makes sense. But I would prefer these to be serialized as List<T> on the client. Is there anyway I can force the wsdl to create this .net specific type? Like a dataset.
The problem is that when an array is bound to a datagrid, its size is fixed meaning I can't do an AddNew as I can for a bound List<T>.
I'm not sure that this is strictly CAB related but any help be gratefully recieved.
Maybe of more interest is that I have a momento pattern function over the state allowing me to do undo functionality, without worring about IEditableObject(I think that's right).
Nov 2, 2005 at 12:38 PM
originally posted by: DLorenz

Well, I would think one way to fix the problem would be to recreate your list by pulling the data out of the array and into a new List<T>... Though, that's probably the last thing you want to do.
Nov 3, 2005 at 7:53 AM
originally posted by: krijn

I think your solution won't work when a view displays multiple smartparts for the same data. This because each BindingSource creates a new currencymanager. Navigation (next,prev, ..)
in one smartpart does not result in child navigation on another smartpart.

Every new BindingSource object results in a new BindingContext ?
Nov 4, 2005 at 5:01 AM
originally posted by: DLorenz

Well, it can work, but you have to somehow raise an event, letting all the smartparts know that a change occured in the object they are bound to. Then each smartpart can rebind its data, showing the change.
Nov 4, 2005 at 6:53 AM
originally posted by: krijn

Raising events on each change of position, new or deleted isn't really an automatic scenario.

I've creating a custom collection of custom bindings where each binding is a simple object :
Class CustomBinding with property's Control, DataSourceName,DataMemberName, PropertyName.

The customBinding object (with lots of designers) listens for component changes, when there are changes (or additions) to a standard BindingCollection of a control this binding gets removed and a new customBinding is created and added to the CustomBinding collection.
For example one usercontrol 'uiCustomers' and a BindingSource 'CustomersBindingsSource':
1. Drag&drop fields from datasource window
2. The customBinding Designer listener creates customBindings instead of databindings
3. the standard generated code : txtName.DataBindings.Add .. is removed and custom code is added to the InitializeComponent : CustomBindings.Add(New CustomBinding(txtName,"Text", "Customers","CustomerName")
4. No 'real' databindings are known at this point
5. Now I can remove all (VS) generated objects that I don't need in the usercontrol : datasets, BindingSource objects, ..
6. In the smartpart (in case usercontrol is used in CAB project) I could create code like this in uiCustomers_Load method :
7. this method loops through all customBinding objects in CustomBindings and creates 'real' databindings like :

What do you think ? Interesting ?