CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Csla Best Practice For Building a Binding Object and WinForm Validation

rated by 0 users
Answered (Verified) This post has 1 verified answer | 2 Replies | 1 Follower

Top 500 Contributor
40 Posts
Matthew Copeland posted on Mon, Nov 28 2011 5:05 PM

Hi,

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.

Thanks,

Matthew

 

 

Answered (Verified) Verified Answer

Top 10 Contributor
1,811 Posts
Answered (Verified) JonnyBee replied on Tue, Nov 29 2011 12:33 AM
Verified by Matthew Copeland

Hi Matthew,

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 CslaContrib Coordinator

All Replies

Top 10 Contributor
1,811 Posts
Answered (Verified) JonnyBee replied on Tue, Nov 29 2011 12:33 AM
Verified by Matthew Copeland

Hi Matthew,

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 CslaContrib Coordinator

Top 500 Contributor
40 Posts

Great stuff!

Thanks Jonny!

Page 1 of 1 (3 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems