Could you explain a bit further about binding the Enabled property to IsSavable. IsSavable doesn't show in my list.
Thanks
ozitraveller:Could you explain a bit further about binding the Enabled property to IsSavable. IsSavable doesn't show in my list.
http://www.lhotka.net/Article.aspx?area=4&id=5faaee8e-8496-4845-86f7-787c6b64096c
That works fine for me. Nearly all my forms have consistently named OK, Apply, Cancel and Delete buttons. I have a helper function that is called from CurrentItemChanged and takes the BO and the form. It looks for the existance of those buttons in the form's Controls collections and sets them appropriately from the BO properties. The function is actually in a base form class that I inherit most of my forms from.
Early on I used direct binding to those properties like you are trying now. I have a class in the inheritance between CSLA objects and my own (always a good idea) and I went against Rocky's plan and made those properties browsable in my inbetween class. That worked okay until I had a root BO on a form with a editable child collection in a grid on the same form. To make it work you need to catch the ListChanged event in the root BO and fire a PropertyChanged event I think it was. This is so that those buttons work correctly when you change a propery on a child object. That caused me a lot of problems with multiple events being fired back at the grid. Cancel especially did not go smoothly. Using the CurrentItemChanged event is very simple and works so much better. Once I did that and followed the other recommendations from Rocky about databinding, things worked beautifully and I've never looked back. See the articles about doing EndEdit and CancelEdit on the bindingSource, not your BO, and doing these in the correct order if you have root and child.
As an optimisation (probably not really worth the trouble but ...) my forms have a bool flag allows me to enable or disable the setting of button state on CurrentItemChanged. Some things like Cancel can cause a lot of events but you really only need the buttons set once when its done so I disable the updating, do the Cancel and then call my button update function once.
Cheers
Ross
Copyright (c) Marimer LLC