StrataFrame Forum

Change control disabled state to readonly

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

By dgsoft - 1/24/2010

Hi,

The default behavior of controls when editable state of business object is false - controls are disabled.

When it so, I can't use shortcut menu to copy text values and so on. The question is :

Is there EASY WAY Smile to change controls behavior so controls instead disable set to readOnly.



Thank you

Denis
By Greg McGuffey - 1/25/2010

Try subclassing and overriding the BindingEditable property. Inside it, set the textboxes readonly state (instead of its enabled state). I not feeling well today, but when I feel a bit better, I'll check my code....I think I've done this....
By dgsoft - 1/27/2010

Smile yes.. I see.. but subclassing I just don't call "easy way" to solve the problem . Smile
By Trent L. Taylor - 1/28/2010

If you set the ManageUIReadonly state of the BO to false, the fields will never be automatically disabled based on the edit state. I think that this is what you are looking for. Also, you can do this on a per control basis also by setting the IgnoreUIReadonlyState property of an individual control to false.
By Larry Caylor - 1/28/2010

Many of the standard Windows controls (from which the SF controls are inherited) do not have a ReadOnly property. This is one of the reasons that I use a lot of the Infragistics controls since I feel it is easier to read controls that are in ReadOnly state than controls that are disabled. I have my own version of the SF Infragistics wrapper that uses ReadOnly in place of Enabled for those controls that support it. I also modified the wrapper to set the default IgnoreManagedReadOnlyState to False instead of True so that it matches the default of the standard SF controls (not sure why they are differentWhistling ) Since the SF wrapper seldom changes and I tend to use the most recent version of the Infragistics controls, having to maintain and re-comple the code is not a problem for me. It would be nice if the standard SF Infragistics wrapper worked this way but changing it now would probably cause problems for other SF users.
By Greg McGuffey - 1/28/2010

If you just want the controls to always be enabled, then Trent's suggestion is very easy.



However, if you do want them to be unavailable until the user explicitly edits a record and just change TextBoxes to become readonly rather than disabled, so you can select text and scroll with multiline textboxes, then sub-class is a nice way to go.



yes.. I see.. but subclassing I just don't call "easy way" to solve the problem . Smile




Actually it is very easy. Here the entire class:





using MicroFour.StrataFrame.UI.Windows.Forms;

public class TextBox : Textbox, IBusinessBindable

{

  public TextBox() { }



  // This replaces the BindingEditable property of the base class with out own.

  // This changes the ReadOnly property rather than the enabled property, which

  // allows for text to be selected and for scrolling.

  public new bool IBusinessBindable.BindingEditable

  {

    get { return !this.ReadOnly; }

    set { this.ReadOnly = !value; }

  }

}




I've attached a solution. This uses the StrataFrameSample db and shows how the standard SF Textbox behaves and how a readonly one would work. It also shows another way to go, handling the EditingStateChanged event of the BO and manually setting the readonly state (not what Trent was talking about...but I was confused for a bit Blink ).



I hope one of these ways gets you going!