Validation... I have a cunning plan, m'lord...

Validation... I have a cunning plan, m'lord...

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


FreeAsInBeer posted on Thursday, April 19, 2007

I've been think of doing this, and thought i'd discuss it here first (n heads are better than 1, esp when the 1 is mine)

I want to give feedback to my users that an object IsNew, IsSavable, and maybe the rest.

Instead of creating a custom control, I was thinking of adding a validation rule for IsNew. If it is new, I'd add a validation error with a severity of Warning.

Has anyone done this, or see any problems? I've implemented it, and it works fine (so far).

RockfordLhotka replied on Friday, April 20, 2007

I can't see a problem with this, other than the Is___ properties aren't bindable (they are marked with the Browsable(false) attribute).

Stephen Richards replied on Friday, April 20, 2007

Why is this?  It would be nice to be able to bind the Save button to the IsSavable property.

I searched for "bindable" in the ebook version of the VB book and the only hint I found is that one ObjectFieldInfo object is created for each bindable property on a business object (p. 320).

RockfordLhotka replied on Friday, April 20, 2007

The use of Browsable(false) is discussed in Expert VB/C# 2005 Business Objects. The reason for using the attribute is to prevent the Windows Forms designer from including these properties (IsNew, IsDirty, IsDeleted, IsValid, IsSavable) from showing up when you drag-and-drop an object onto a form to set up the form's data binding.

It is a convenience in most cases, because otherwise you have to go remove those 5 properties from every object before you can set up data binding (typically you don't want 5 checkbox controls on every form and in every grid).

Unfortunately, unbeknownst to me and to the PM who owned the Windows Forms data binding designer at the time, Browsable(false) not only hides the properties from VS, but it actually makes the properties not bindable... This has been discussed on this forum a couple times before, and it came as quite a surprise to both me and the PM.

However, in Windows Forms there's a very reasonable workaround as described here. So my feeling is that it is better to leave the Browsable(false) attribute in place and use the workaround, than to remove the attribute and have to manually remove those 5 properties every time you want to create a form or grid.

In Web Forms this is a non-issue, because people don't typically bind to these properties. And in fact, removing Browsable(false) would mean that web developers would also have to remove the 5 properties manually each time they set up a GridView or DetailsView control. So again having the attribute is a net gain imo.

In WPF I have created an objectstatuspanel control that makes these 5 properties available for binding to controls. I think this is the best of both worlds, because you can use data binding against your business properties as normal, and if you want access to the 5 status properties you can easily get at them.

Jimbo replied on Sunday, April 22, 2007

Rocky,
 I think that you should also emphasize that in the binding source currentItemChanged event you can call 'ApplyAuthorizationRules' where the control enabling is centralised.

Jimbo

Copyright (c) Marimer LLC