By Ben Kim - 1/24/2007
When designing a form, one of our requirements is to allow the end user to enter text such as "Police Uniform" for a description. However if the user types "Police Uniform " (spaces), we want to trim the field. So I turn on Trim Right in the BO. Now I cannot type a space after the letter "e" in police. So I was advised to change the BindingUpdateMode to "OnValidation". Now when I add a new record, type in a description like above, the description is NOT saved and is blank in the database and is displayed as blank on the UI form! What gives? Ben
|
By StrataFrame Team - 1/25/2007
The OnValidation DataSourceUpdateMode has issues... only certain actions within .NET cause the control to update. If the description was the last field you entered, and you immediately click the save button after you enter the field, the validation will not fire. Hence, we default the DataSourceUpdate mode to OnPropertyChanged. Your best bet is probably to remove the auto-trim option from the field on the BO and trim the value within the CheckRulesOnCurrentRow event.Me.fld_Description = Me.fld_Description.Trim()
|
By Ben Kim - 1/25/2007
I appreciate the workaround - however we have thousands of string fields! Is this issue going to be addressed any time soon?Ben
|
By Trent L. Taylor - 1/25/2007
There really isn't a whole lot we can do. The problem you're running into is a .NET binding issue. The .NET data binding does not always properly fire the OnValidation method, additionally, this is how the .NET data binding interacts with the control. The problem that you're running into is a .NET issue.We can add this to the "to-look-at" list, but I make no guarentees that this will change until a future release of .NET.
|
By Greg McGuffey - 1/25/2007
What about adding a setting in the BO Mapper that would just add the code mentioned automagically?
|
By Trent L. Taylor - 1/25/2007
In this example you would never be able to add a space.
|
By Ben Kim - 1/25/2007
I think what Greg is saying, instead of doing the Trim'ing the way StrataFrame currently does it, why not add code to the .Designer file automatically that will .Trim each field correctly before saving the entry (Insert, Update) based on the Trim setting in the Business Object Mapper?Ben
|
By Greg McGuffey - 1/25/2007
Yep, that is what I'm saying. 
Why not just add an event handler automatically to handle the CheckRulesOnCurrentRow in the designer? The user could have another handler. They would just have to be clear that trimmed fields might or might not yet be trimmed.
|
By Ben Kim - 1/25/2007
Trent,You are correct. I cannot type something like "Police Officer" because the BO keeps trimming the space much like setting it up via the Business Object Mapper. So what do you suggest? Here is what I want: User types "Police Man " (trailing spaces) We automatically trim the field to "Police Man" Ideas? Ben
|
By Trent L. Taylor - 1/25/2007
You're wanting an automated solution for something that will take some engineering. This will have to be done at the BO level or require a change to the textbox control. You can create your own textbox by inheriting the StrataFrame textbox. In the Validating event you could manage this. (I would recommend having a property to determine whether or not to do anything.
|
By Ben Kim - 1/29/2007
Can you give me an idea which method I should add to the BO's that would handle this? I tried in the CheckRulesOnCurrentRow and it does not allow me to add a words with spaces. You said it could be done in the BO OR a custom TextBox. I would much rather take care of it at the BO level.Also, if this is the functionality of the Trimming options of the framework, what good are they besides trimming left? I assumed the trimming was handled during the "save" operation and not during entry. Ben
|
By Trent L. Taylor - 1/29/2007
If you change the textboxes BindingUpdateMode to OnValidation, then you can use the trimming as you would like. There is one problem though, you must validate the field before the changes are commited to the property. So if you make a change and tab, it will definitely work. But if you make a change and then click the Save button on a MaintenanceFormToolstrip (without tabbing), it may not fire the validation.You can handle the BeforeSave event and force the textboxes to validate.
|
By Ben Kim - 1/29/2007
(Sorry I posted this in the wrong newsgroup (issues))I am adding the code to BeforeSave as you suggested. How do I fire a validate event for controls correctly so the BO properties get updated with the new values? For Each lcItem As Control In Me.Controls What goes here? I do not see an lcItem.Validate() option Next Thanks! Ben
|
By Ben Kim - 1/30/2007
Hello,I am trying to prove that the validated event is indeed not firing. The original thread was about data saving and the OnValidation setting. I added message boxes to the LostFocus event and the Validated for the textbox not updating when the BindingUpdateMode is set to OnValidation. The message boxes both display regardless if I tab out of the control or go directly and click the SAVE button on the maintenance form. Where in the .NET framework is this a problem? Is it internal or something that can be corrected via code? Ben
|
By StrataFrame Team - 1/30/2007
I am not exactly sure where in .NET the problem is... however, if you place a breakpoint in the Set of your bound property, it will not always be reached depending upon how you exit out of the bound control. You could use a tool like Reflector to look into the .NET assemblies and check the System.Windows.Forms.Binding object and see how it behaves when the DataSourceUpdateMode is set to OnValidation.
|
By Ben Kim - 1/30/2007
Yes I can see via the debugger the setvalue is not being reached. Has this issue been reported to Microsoft and is there a knowledge base article that details this behavior? It would be helpful to me so I can present it to the higher ups.Ben
|
By StrataFrame Team - 1/30/2007
I'm not sure whether there is a MS knowledge base article on the problem. From what I have been able to tell personally, if you change the focus from one control to another control, the event fires. However, ToolStripMenuItems do not derive from Control, they derive from Component, so they cannot hold focus, and the focus is never switched from the textbox to the button, so the Validating/Validated events never fire on the textbox. It's more of a design issue than a bug, and I'm sure that if you register a bug report with MS, they will just mark it with "By Design" and close it.
|
By Ben Kim - 1/30/2007
OK, so how do I manually fire the event(s) in the BeforeSave?So far I have: For Each lcControl As Control In Me.Controls WHAT GOES HERE? Next I have tried RaiseEvent but it complains that I cannot call base class events directly. Ideas? Ben
|
By StrataFrame Team - 1/30/2007
You can raise the event from within the control by calling Me.OnValidating() or Me.OnValidated(). However, those methods are protected, so you will have to create your own textbox control and create public methods that call the protected methods. Or you can use reflection to get the MethodInfo and invoke it on the control. Reflection is slow and requires a good bit of code to execute a single method, but you can do it from anywhere.
|