Using Binding Sources with Business Base

Using Binding Sources with Business Base

Old forum URL: forums.lhotka.net/forums/t/5276.aspx


bcrowell posted on Wednesday, August 20, 2008

These bindingsource controls look great. However, I seem to be missing something. From what I can tell, when you configure one of the controls and set its datasource to a CSLA business object (or any other type for that matter) the BS only provides access to the top level properties (as opposed to inherited properties). So things like IsDirty and IsNew are not available for binding to UI controls via the BS.

So far I've added what I'm calling shadow properties on my csla bizobjects that bring these BusinessBase members up to the top level but these seems like a waste of time and complexity. Am I missing something. Is there another way to expose the BusinessBase proerties via a BindingSource?

Thanks a million.

Byron

RockfordLhotka replied on Wednesday, August 20, 2008

This article may be helpful

http://www.lhotka.net/Article.aspx?area=4&id=91e15def-fa1c-4236-86b5-b204bfc4a0aa

The properties aren't bindable because they have the Browsable(false) attribute on them. This is intentional, because otherwise they'd always appear when you use drag-and-drop binding, or bind a collection to a grid.

In other words, you'd have to remove 5-6 properties from every UI scenario if they were bindable.

So I've traded on set of pain for another, because it does make it harder to bind IsSavable to a button control, and other similar scenarios. But I think that is less painful than having to muck around with every UI and every grid to get rid of all the properties on every object that you rarely want to show.

bcrowell replied on Thursday, August 21, 2008

That makes sense. So would you recommend implementing a shadow property idea on each bizobject for those base properties or is there a good way to override the Browsable(false) setting in code.

Thanks Rocky.

tetranz replied on Thursday, August 21, 2008

bcrowell:
That makes sense. So would you recommend implementing a shadow property idea on each bizobject for those base properties or is there a good way to override the Browsable(false) setting in code.

I use the method that Rocky describes here to enable and disable those buttons. I initially did exactly what you're doing with shadow properties so I could bind to them but I ran into performance issues. It's long ago now and my memory is getting dim but I think now it may have been related to databinding behaving badly when I was bubbling up ListChanged events from child collections. That's been a recent topic here relating to CSLA 3.5.

Everything went smoothly once I stopped trying to bind to those properties and simply updated the button properties on the bindingSource CurrentItemChanged event. To reduce code, I have a standard helper method that takes a form and a BO and updates the buttons based on standard button names. I also have a flag to disable the updating when I'm binding and unbinding since I noticed that the CurrentItemChanged event happens many times so you really only need to update the buttons once when the operation is done.

bcrowell replied on Friday, August 29, 2008

That's really helpful. Many thanks.

Byron

Copyright (c) Marimer LLC