StrataFrame Forum

Best way to make a bound control readonly?

http://forum.strataframe.net/Topic11495.aspx

By thegwill - 9/15/2007

I have a business object with a bound field that I display in a form. The field value is populated in code (as a default value for the BO) so the user should not be able to change it although they do need to see it

By defult, when editing, the control becomes enabled. I have remedied this by implementing the EditingStateChanged event on the BO instance on my form and explicitly setting the UI control.Enabled to false

Question is: this works but is there a better way to do this?

By Larry Caylor - 9/16/2007

The easy way is to set the controls Enabled property = false and the IgnoreManagedReadOnlyState = true. This will prevent the control from being enabled when the bound object is being added or edited.

-Larry

By thegwill - 9/17/2007

Thanks - I'll give it a try
By Trent L. Taylor - 9/17/2007

Larry is correct, you could do that.  Another option is to make the property read-only.  This will prevent the end-user from being able to modify that field as well.  If this is a field that is pulled from the schema, you can assign this through the BO Mapper (it is a check box).  If it is a custom property just assign it as read-only.  The simplest option though may be Larry's suggestion if this is going to be a one time thing.