StrataFrame Forum

How to force ToUpper a value entered by end user?

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

By Edhy Rijo - 11/14/2007

Hi All,

I have a field name State, and I want that the value entered by the end user is force to Upper case.  What would be the best approach for this?

I know I can trap the control's TextChanged event and change the value there, but I am looking for a cleaner solution at the BO level so I don't have to do the modification in all form's this field may be used. 

I wish the Business Object Mapper could handle this kind things pretty much the way they handle the Trim.  It looks obvious to me this could be done in the BOM as an enhancement.

By Paul Chase - 11/14/2007

Hi,

As usual there is more that one way to skin a cat. I personally would use the last option , I kinda went from what I feel is least desirable to most.

1.) There is a property on a text box for setting  the casing to upper so you should not have to do anything more than set the property.

2.) You could also subclass a text box or whatever control you are using and write whatever formatting code you want in your inherited class then use that inherited class wherever you need that functionality.

3.) You can also copy the property out of the .designer file and in the custom code section paste it

then add code to the SET portion of the property to set the value to upper.

 

4.) You can also have the business object raise its field's changing event and handle it. 

 Private Sub BusinessObject1_FieldPropertyChanging(ByVal sender As Object, ByVal e As BusinessObject1FieldChangingEventArgs) Handles Me.FieldPropertyChanging
        If e.FieldChanging = BusinessObject1FieldNames.MiddleName Then
               e.FieldValue = e.FieldValue.ToString.ToUpper
        End If
    End Sub

Hope that helps

Paul

By Edhy Rijo - 11/14/2007

Hi Paul,

Thanks for the several options, I am trying option 4 with the following code:

Private Sub CustomersBO1_FieldPropertyChanging(ByVal sender As System.Object, ByVal e As ATR_BO_Library.CustomersBO.CustomersBOFieldChangingEventArgs) Handles CustomersBO1.FieldPropertyChanging

If e.FieldChanging = ATR_BO_Library.CustomersBO.CustomersBOFieldNames.State Then

e.FieldValue = e.FieldValue.ToString.ToUpper()

End If

End Sub

But, when typing anything in the textbox, the cursor keeps going to the beginning of the textbox, so if I am type ny, I will get YN.  Is there any other trick I can use propery enter ny and get NY in the textbox and field property?

By Edhy Rijo - 11/14/2007

Paul,

Testing option 1, by setting the textbox property CharacterCasing = Upper will give me the results I wanted, which is to force the value entered in this textbox to be upper case.

But if you or anybody else don't mind, I still would like to have this controlled at the BO level, so I don't end up having to set things in a lot places and try to keep all coding at the BO level in one place.  This need to have this field upper case is a rule of the application and should fall into the business object.

By Paul Chase - 11/15/2007

You would need to add code to handle the text changed event in your base class to force the textbox to stay at the end. You could also probably simply handle the before save event and set the field's value there. I was working from home last nite and did not think.  

Private Sub BusinessObject1_BeforeSave(ByVal e As MicroFour.StrataFrame.Data.BeforeSaveUndoEventArgs) Handles Me.BeforeSave

Me.fieldname = Me.fieldname.ToUpper

End Sub

 

 

Public Class AL_TextBox

Inherits MicroFour.StrataFrame.UI.Windows.Forms.Textbox

#Region "Constructor"

Public Sub New()

InitializeComponent()

End Sub

#End Region

#Region " Init Component"

''' <summary>

''' Set any default property's

''' </summary>

''' <remarks></remarks>

Private Sub InitializeComponent()

'-- You can set here as a default for all your text boxes

Me.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper

End Sub

#End Region

''' <summary>

''' This forces the cursor to always go to the end of the text

''' </summary>

''' <param name="sender"></param>

''' <param name="e"></param>

''' <remarks></remarks>

Private Sub AL_TextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.TextChanged

' Declare variables

Dim LoTextBox As MicroFour.StrataFrame.UI.Windows.Forms.Textbox = sender

LoTextBox.Select(LoTextBox.Text.Length, 0)

End Sub

End Class

By Edhy Rijo - 11/15/2007

Hi Paul,

Once again, thanks a lot for the sample code and the instructions, it does help specially when you know how to do all this in other programming tool like VFP (for over 20 years) and now learning the new stuff can be frustrating sometimes.

I will take the class approach since I want the user to see the typed character in upper case.  But I am saving all other suggestions in my file bag for future use.  Hehe

By Paul Chase - 11/15/2007

I know the feeling I am converting a FPW 2.6 \ VFP app to .Net. what really-really sucks is when I have to go in and make changes to the 2.6 code.. no intellisence etc.. It's like being forced to watch black and white television.BigGrin.

Once you get used to .Net it is great it just takes a little time getting over that curve, also the Fox Frameworks had many-many years to add all these nifty types of features.

By Ivan George Borges - 11/15/2007

I know the feeling I am converting a FPW 2.6 \ VFP app to .Net.

Good to know I'm not alone in this boat... Satisfied

By StrataFrame Team - 11/19/2007

Edhy,

The FieldChanging event option will work if you set the DataSourceUpdateMode to OnValidation rather than leaving it on the default of OnPropertyChanged.  But then you might run into the other issues discussed with the toolstrip not being a control (I think that was you that I was discussing that with...).

Leaving it on OnPropertyChanged causes it to copy the value back to the business object each time the value in the textbox changes, and when the value is different and copied back to the control, the cursor changes...

By StrataFrame Team - 11/19/2007

It looks obvious to me this could be done in the BOM as an enhancement.

Yes, it is likely that in the future we will store information like this off in the meta-data of the fields in the bo and set the property on bound textboxes to force it to upper case.

By Edhy Rijo - 11/19/2007

Hi Ben,

Thanks for the response.  In this case setting the textbox property CharacterCasing = Upper was the easiest way for me to get the results needed. 

Just keep in mind that since I come from a VFP framework environment with many features, I will always try to suggest ways to enhance SF with features I missed from my VFP framework experience.