Winforms GUI disabling form fields when in unknown state

Winforms GUI disabling form fields when in unknown state

Old forum URL:

Warren posted on Tuesday, May 06, 2008

Hi All,

I have been stumbling around for a long time trying to figure out the best way to deal with enabling
and disabling text fields on the forms of my WinForms application. In particular, I have been unable find a 'clean' way that allows me to disable form fields when a the form is first loaded and I don't
know whether the user wants to add, change, delete or just view a record. Right now I am creating
a new object in the form load event which puts the form in 'new' mode. This works but the users do
not want the forms to automatically open in 'new' mode.

My design is based on Ptracker and I have the new, cancel, save buttons working smoothly thanks
to BindingSource_CurrentItemChanged, CanEditObject, CanDeleteObject IsSaveable, and IsDirty et al.

Any ideas on how to best start up a form with the text fields disabled without having to write
enabled = False/True throughout my form button handling code?  What are others doing in this situation.

Thanks in advance

JonnyBee replied on Wednesday, May 07, 2008


1: Use databinding. The Enabled/Visible and other properties may also be databound so that you may have enabled of controls databound to one or more properties on your BO or Controller.
2. Override the CanWriteProperty in your BO to return false when edit is not allowed (thereby making your BO/porperties ReadOnly) and use the ReadWriteAuthorizationManager to set UI Controls enabled/disabled.


Copyright (c) Marimer LLC