Field Events |
Scroll |
The Thereforeā¢ AddIn system provides several field events in the Thereforeā¢ category dialog.
The example below tracks information about the currently focused and the last modified field and writes it into the Info Field. The CategoryFieldVerify event is handled to invalidate the category dialog if the InvoiceNo field contains the character x.
|
Requirements and Assumptions:
Visual Basic Imports System.Runtime.InteropServices Imports System.IO Imports Therefore.API
<Guid("255482B8-AE9A-4395-A4C7-F0009F6A8510"), ComVisible(True), ClassInterface(ClassInterfaceType.None)> _ Public Class FieldEventAddIn Implements ITheAddIn
Private focusedFieldNo As Integer = 0 ' Focused field number Private modifiedFieldNo As Integer = 0 ' Last modified field number Private modifiedValue As String = "" ' Last modified value (as string)
Public Sub GetHandledEvents(ByVal client As TheClientType, ByVal eventSet As TheEventSet) Implements ITheAddIn.GetHandledEvents ' Register for all filed events eventSet.Add(TheEventType.CategoryFieldChanged) eventSet.Add(TheEventType.CategoryFieldVerify) eventSet.Add(TheEventType.CategoryFieldGotFocus) eventSet.Add(TheEventType.CategoryFieldLostFocus) End Sub
Public Function HandleEvent(ByVal e As TheEvent) As Integer Implements ITheAddIn.HandleEvent Dim fieldNo As Integer = e.ObjectID Select Case (e.EventType) Case TheEventType.CategoryFieldChanged modifiedFieldNo = fieldNo modifiedValue = e.IndexData.GetValueByFieldNo(fieldNo).ToString UpdateInfo(e) Case TheEventType.CategoryFieldVerify ' Invalidate the InvoiceNo field if it contains an 'x' If ((e.ObjectName = "InvoiceNo") AndAlso e.IndexData("InvoiceNo").ToString.Contains("x")) Then Return 1 End If ' Display standard error message and force the user to correct the field value Case TheEventType.CategoryFieldGotFocus focusedFieldNo = fieldNo UpdateInfo(e) Case TheEventType.CategoryFieldLostFocus focusedFieldNo = 0 UpdateInfo(e) End Select Return 0 End Function
' Update the info field in the category dialog Private Sub UpdateInfo(ByVal e As TheEvent) e.IndexData("Info") = String.Format("Foc[{0}], Mod[{1}] = {2}", focusedFieldNo.ToString, modifiedFieldNo.ToString, modifiedValue) e.CategoryDialog.Update() End Sub
End Class C# using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.Windows.Forms; using Therefore.API;
namespace AddInSamples { [Guid("66354B22-9B4D-4025-ACB5-500E26B8220C"), ComVisible(true), ClassInterface(ClassInterfaceType.None)] public class FieldEventAddIn : ITheAddIn { private int focusedFieldNo = 0; // Focused field number private int modifiedFieldNo = 0; // Last modified field number private string modifiedValue = ""; // Last modified value (as string)
public void GetHandledEvents(TheClientType client, TheEventSet eventSet) { // Register for all field events eventSet.Add(TheEventType.CategoryFieldChanged); eventSet.Add(TheEventType.CategoryFieldVerify); eventSet.Add(TheEventType.CategoryFieldGotFocus); eventSet.Add(TheEventType.CategoryFieldLostFocus); }
public int HandleEvent(TheEvent e) { int fieldNo = e.ObjectID;
switch (e.EventType) { case TheEventType.CategoryFieldChanged: modifiedFieldNo = fieldNo; modifiedValue = e.IndexData.GetValueByFieldNo(fieldNo).ToString(); UpdateInfo(e); break; case TheEventType.CategoryFieldVerify: // Invalidate the InvoiceNo field if it contains an "x" if (e.ObjectName == "InvoiceNo" && e.IndexData["InvoiceNo"].ToString().Contains("x")) return 1; // Display standard error message and force the user to correct the field value break; case TheEventType.CategoryFieldGotFocus: focusedFieldNo = fieldNo; UpdateInfo(e); break; case TheEventType.CategoryFieldLostFocus: focusedFieldNo = 0; UpdateInfo(e); break; }
return 0; }
// Update the info field in the category dialog private void UpdateInfo(TheEvent e) { e.IndexData["Info"] = String.Format("Foc[{0}], Mod[{1}] = {2}", focusedFieldNo.ToString(), modifiedFieldNo.ToString(), modifiedValue); e.CategoryDialog.Update(); } } } |