StrataFrame Forum

Required Fields

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

By Paul Chase - 10/4/2006

I am working on an app where the users would like to easily identify the required fields before getting the required fields error upon save. I was thinking about a different back color or something along those lines.

I haven't really started to poke around on how to accomplish this but am thinking I will need to create a subclass of MicroFour.StrataFrame.Business.BusinessLayer add a property to store the back color.

Then in some Form method\event? add the code to loop through the required fileds collection and the forms controls and set the approriate back colors on the controls that are bound to required fields. So I guess my question is what would be the appropriate event to add the code to do this. Or is there a better way to accompish this?

Any pushes/shoves in the right direction would be welcome.

Thanks

Paul

By StrataFrame Team - 10/4/2006

You could either change the back color or use your own ErrorProvider with the icon set to a little green dot or yellow arrow.  Your best bet would probably be to add this functionality to the business object in the inherited class you were talking about.  In the EditingStateChanged event of the business object, you could cycle through the BoundControls collection of the business object and compare the bound field to the required fields collection and if it's required, then add your adornment.
By Paul Chase - 10/4/2006

Ben,

I was thinking about this a bit more. I think I only need to show that the controls are required feilds when a user adds a new record. Thanks for suggesting the error provider I think it will look a bit nicer. 

Thanks

Paul

By StrataFrame Team - 10/4/2006

No problem.  The error provider is just a basic .NET control, in case you didn't already know that Smile
By Paul Chase - 10/5/2006

Thanks again Ben I implemented it this morning and it works like a champ.
By Ben Kim - 11/8/2006

Would you care to share this code with this "Newbie"?  That is actually a requirement we have for our applications also.  Perhaps this should be an option in StrataFrame? ;-)

Ben

By Trent L. Taylor - 11/8/2006

It would look something like this...this is not tested, I just typed it in here.  This code would go in your business object...so you would more than likely want to create a subclass of BusinessLayer so you only have to write this code once:

Private _RequiredProvider As ErrorProvider

    Public Sub ShowRequiredFields()
        '-- Establish Locals
        Dim loItem As MicroFour.StrataFrame.Business.IRequiredField
        Dim loControl As Control

        _RequiredProvider = New ErrorProvider(CType(Me.ParentContainer, ContainerControl))
        _RequiredProvider.Icon = YourIconFile
        ' Place any addition provider settings

        '-- Cycle through the required fields
        For Each loItem In Me.RequiredFields
            '-- Get the control
            loControl = GetBoundControl(loItem.FieldName)

            If loControl IsNot Nothing Then
                _RequiredProvider.SetError(GetBoundControl(loItem.FieldName), "Required Field")
            End If
        Next
    End Sub

    Private Function GetBoundControl(ByVal FieldName As String) As Control
        '-- Establish Locals
        Dim loControl As Control = Nothing
        Dim loItem As MicroFour.StrataFrame.UI.Windows.Forms.IBusinessBindable

        '-- Cycle through the bound controls
        For Each loItem In Me.BoundControls
            If loItem.BindingField.Equals(FieldName) Then
                loControl = CType(loItem, Control)
                Exit For
            End If
        Next

        '-- Return Results
        Return loControl
    End Function

By Greg McGuffey - 11/9/2006

Ben Kim (11/08/2006)
That is actually a requirement we have for our applications also. Perhaps this should be an option in StrataFrame? ;-)




I'll second this! BigGrin
By Chan - 1/25/2007

I second this too!



Tongue
By Larry Caylor - 1/25/2007

I’d also like to see this as part of the standard framework. And while we’re talking enhancements, I’d still like to see support for warning messages. I’d like to be able to strongly suggest to the user that a field should be entered using a business rule, but not prevent them from saving the object if the field is left blank.

-Larry

By Greg McGuffey - 1/25/2007

Excellent idea! BigGrin