Recorgnize the Modus change?
martinsalo
Hello Forum,
I have some ubound (no data source in New Item Menu) textboxes on a form. I fill them with a rule that queries the content.
My problem is: The user changes from Ok mode to another mode and the old (invalid) content of the textboxes are still showing. I want to write another rule that clears the content of the textboxes, if the user leaves the OK mode. So how can I recognize the change?
I have tried every Event in Inner and Before mode: With a rule that shows a Textbox if triggered. If the user is in OK mode and clicks in the Toolbar on Find or Add, no Event is triggered! No Textbox is showing.
How can I get a message if the user changes the form mode?
Thanks
Martin
martinsalo
I have created a rule that adds a event handler to menu Items in the LoadForm event:
// Authour: Martin Salo 23.Dez 2014
// Description:
/* There are unbound TextEdit controls on several document forms. If the form shows for
example a invoice, queries are made to fill the TextEdit controls with additional data.
Problem: If the user changes the from mode {Update, OK} to {Find,AddNew}, the TextEdit
controls are still filled with the last shown data.
Solution: Write a rule that clears the TextEdit controls.
This rule adds Eventhandler to menu Items Search and AddNew and clears the TextEdit
controls on switching the mode.
*/
try {
Form DocForm = pVal.Form;
// Create EventHandler:
SwissAddonFramework.UI.EventHandling.MenuEvents.MenuEventHandler MenuClickFunction =
delegate (SwissAddonFramework.UI.EventHandling.MenuEvents.MenuClick eventVal) {
try {
Form CurrentForm = Form.GetFormFromUID(SwissAddonFramework.B1Connector.GetB1Connector().Application.Forms.ActiveForm.UniqueID);
// List of forms where the TextEdit Controls are located:
string[] FormTypes = new string[] {"133","139","140","141","142","143","149","179","180","181","182","60091","1470000200"};
// If ActiveForm has a type from within the list, then clear the TextEdit Content:
foreach (string FormType in FormTypes) {
if (CurrentForm.Type == FormType) {
// Examine the FormMode:
if (CurrentForm.Mode != SwissAddonFramework.UI.Components.ModeComponent.FormModes.OK &&
CurrentForm.Mode != SwissAddonFramework.UI.Components.ModeComponent.FormModes.OK) {
// Clear the TextEdit controls:
TextEdit.GetFromUID(CurrentForm, "NI_00012").Value = "";
TextEdit.GetFromUID(CurrentForm, "NI_00016").Value = "";
TextEdit.GetFromUID(CurrentForm, "NI_00017").Value = "";
}
break;
}
}
} catch (Exception ex) {
MessageBox.Show(ex.ToString(), "Ok");
}
};
// Add event handler to Search menu:
MenuItem.GetFromUID("1281").RemoveAllHandlers();
MenuItem.GetFromUID("1281").AddHandler_Click(
null,
MenuClickFunction
);
// Add event handler to AddNew menu:
MenuItem.GetFromUID("1282").RemoveAllHandlers();
MenuItem.GetFromUID("1282").AddHandler_Click(
null,
MenuClickFunction
);
} catch (Exception e) {
string ExceptionStr = "Exception (R024): " + e.ToString();
customize.Messaging.StatusBar.WriteError(ExceptionStr);
MessageBox.Show(ExceptionStr, "Ok");
}
return true;
Please sign in to leave a comment.
Comments
0 comments