Vibrant discussion about CSLA .NET and using the framework to build great business applications.
I am currently developing a Windows Forms project with Csla 3.8.3.
Up until this point I have been using BindingSource and building the UI control Bindings using the property grid. (The magic of not having to code!)
Of course, in the background, the designer is coding BInding objects for me with a default configuration.
DataSourceUpdateMode = OnValidation FormattingEnabled = true
I ran into an issue when trying to code my own binding for a combo box with a NameValueList as a datasource. The problem turned out to be DataBindings.Add() defaults FormattingEnabled = false.
I realized that at the end of the project I will have thousands of Bindings created without thought towards the potential impact of how those Bindings are configured. A new unknown requirement may not like that configuration!
Has anyone run into problems with Bindings using DataSourceUpdateMode.OnValidation?
Given Csla validation subsystem is DataSourceUpdateMode.OnPropertyChanged a better choice?
Is it best practice to bypass the standard winforms validation subsystem when using Csla?
My instinct tells me mixing the two could lead to confusion during maintenance.
These are just my personal preferences for Windows Forms developement (and I've been doing this for the last 6 years):
1. My preference is for default update mode (OnValidation). This is (almost) required in order to use LookupRules/AsyncLookupRules. 2. When user story requires OnPropertyChanged - then also add a unit test to test to the the form so no-one accidentally changes the update mode - or add code in form constructor after Initialize to set/override the default updatemode programmatically. 3. Null values can be cumbersome in databinding and I sometimes override the nullvalue too on the DataBinding. This must be done in code. <binding>.NullValue = string.Empty; is not possible to set in the designer. 4. In a few specific DataBindings I have also had to hook into the OnParse/OnFormat events - the function is similar to a ValueVonverter in Xaml.
OnValidation means that the BO field value will be updated when focus leaves the current control AND when the next control to get focus has CausesValidation set to true (and that des not have to be first control that gets focus). OnPropertyChanged means that the BO field value will be updated for every keystroke the user enters control.
I also recommend to read the entire DataBinding FAQ available from WindowsClient.Net as well as to look into the samples download.
Jonny Bekkum, Norway