StrataFrame Forum

Managing Control Editing State

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

By Larry Caylor - 2/2/2008

I'm creating a workflow application and one of the requirements is that the ability to edit individual fields of an object varies depending on the current status of the object in the workflow. This can be done in in the UI but I'm looking for a way to manage it at the BO level and let the SF data binding handle the read only state of the fields on the form. Is this doable? I've tried setting the BindingEditable property of the bound control to false but that didn't work. I also took a look at the ProperyDescriptor but didn't find anything that would work.

-Larry

By Larry Caylor - 2/2/2008

OK after a little more experimenting I found that the BindingEditable property is observed if the IgnoreManagedReadOnlyState for the control is set to True; so I can get the behaviour I'm looking for by setting both properties at the BO level.

Which leads to another question; my knowledge of system.predicate is pretty much zeroUnsure. How do I find the index of a bound control in the BoundControls collection given the field name?

-Larry

By Trent L. Taylor - 2/5/2008

Sorry for the delay on this...I missed this post.  You could create a method to enumerate through the bounds controls.  To cycle through the collection, just do this.  You can then type of the "item" as a control to changed the editing state if you ned to.

For Each Item As MicroFour.StrataFrame.UI.Windows.Forms.IBusinessBindable In Me.BoundControls
       If Item.BindingField.Equals("MyFieldName", StringComparison.OrdinalIgnoreCase) Then
           CType(Item, System.Windows.Forms.Control).Enabled = False
       End If
Next
By Larry Caylor - 2/5/2008

Thanks for the explanation; that's basically what I ended up doing. I was just wondering if there was a better way then simply looping through the collection. 

To get the functionality I was looking for I ended up subclassing BusinessLayer, created a list of NonEditableFields, and added methods to Add, Delete, and Clear the list. As the list is updated I update the BoundControls and refresh the Field/s. However since I also want to reference the field names using the field enums generated by SF, things got a little messy since to do that I have to add shadow methods to the inherited BO that in turn call the methods in my custom BusinessLayer. I solved that by creating my own custom template and adding it to visual studio.

Which brings me to; it would be nice if SF provided this functionality, so I wouldn't have to mess with custom templates. Also the logic could be combined with ManagedReadOnlyState which would be a cleaner solution. Or maybe there is a simpler solution that I haven't thought of.