Edhy Rijo
|
|
Group: StrataFrame Users
Posts: 2.4K,
Visits: 23K
|
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.
Edhy Rijo
|
|
|
Paul Chase
|
|
Group: Forum Members
Posts: 414,
Visits: 2.8K
|
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
|
|
|
Edhy Rijo
|
|
Group: StrataFrame Users
Posts: 2.4K,
Visits: 23K
|
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.FieldPropertyChangingIf e.FieldChanging = ATR_BO_Library.CustomersBO.CustomersBOFieldNames.State Thene.FieldValue = e.FieldValue.ToString.ToUpper() End IfEnd 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?
Edhy Rijo
|
|
|
Edhy Rijo
|
|
Group: StrataFrame Users
Posts: 2.4K,
Visits: 23K
|
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.
Edhy Rijo
|
|
|
Paul Chase
|
|
Group: Forum Members
Posts: 414,
Visits: 2.8K
|
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.BeforeSaveMe.fieldname = Me.fieldname.ToUpperEnd Sub Public Class AL_TextBoxInherits 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 boxesMe.CharacterCasing = System.Windows.Forms.CharacterCasing.UpperEnd 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 variablesDim LoTextBox As MicroFour.StrataFrame.UI.Windows.Forms.Textbox = senderLoTextBox.Select(LoTextBox.Text.Length, 0) End SubEnd Class
|
|
|
Edhy Rijo
|
|
Group: StrataFrame Users
Posts: 2.4K,
Visits: 23K
|
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.
Edhy Rijo
|
|
|
Paul Chase
|
|
Group: Forum Members
Posts: 414,
Visits: 2.8K
|
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. . 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.
|
|
|
Ivan George Borges
|
|
Group: StrataFrame MVPs
Posts: 1.9K,
Visits: 21K
|
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...
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
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...
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
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.
|
|
|