How to control keyboards events in Add-in


With Microsoft Dynamics NAV Role Tailored Client we’ve received possibility to add ControlAddIn to any field on page. This opens huge possibilities to extend functionality with own controls.
We can create any .Net control with Visual Studio, register it in NAV controls and add it to any field on page by describe control name in field “ControlAddIn” property.
Then whenever user put focus on this field, NAV forwards full control to AddIn and now AddIn does whatever it wants.

And here comes first issue: if AddIn controls everything then all NAV shortcuts are not active and then what to keyboard key to click if want to go on page to next field/control? Only way is to use mouse and click on another control. This is not best way for UX, especially if you want to do that fast.

Issue was resolved with Cumulative Update 9 for Microsoft Dynamics NAV 2013 R2 (Build 37221) released in July 2014.
https://mbs.microsoft.com/partnersource/global/deployment/downloads/hot-fixes/NAV2013R2PlatformHotfixOverview
With this update NAV keyboard events are left for NAV – user can scroll per controls like in any other page.

But here comes another issue: what to do if we want to leave some keyboard events to AddIn? For example we are using RichTextBox in AddIn for text managing, here <enter> key splits line and jumps to new line. But with CU9 cursor jumps to next page control as <enter> is used by NAV. What to do? We need something flexible: leave event to NAV or to AddIn depends what addin does.

Here comes Cumulative Update 14 for Microsoft Dynamics NAV 2013 R2 (Build 38801) released in December 2014. It allows us to choose where <enter> must to be: in NAV or in Addin.

With this update new interface is implemented in Microsoft.Dynamics.Framework.UI.Extensibility, it is “IControlAddInEnterKeyHandler”. And now we can decide how <enter> key is acting,
will cursor stay in AddIn control

public class ControlAddInWithKeyboardFilter : StringControlAddInBase, IControlAddInEnterKeyHandler

    {

        private RichTextBox rtb;

                 public override bool AcceptsEnterKey

        {

            //get { return false; }

            get { return true; }

        }

  

        protected override Control CreateControl()

        {

            rtb = new RichTextBox();

            rtb.Multiline = true;

            return rtb;

 

        }

 

Or cursor jumps to next NAV control:
  public class ControlAddInWithKeyboardFilter : StringControlAddInBase, IControlAddInEnterKeyHandler

    {

        private RichTextBox rtb;

 

                public override bool AcceptsEnterKey

        {

            //get { return true; }

            get { return false; }

        }

 

       

 

        protected override Control CreateControl()

        {

            rtb = new RichTextBox();

            rtb.Multiline = true;

            return rtb;

         }

 

 

These postings are provided “AS IS” with no warranties and confer no rights. You assume all risk for your use.

Gedas Busniauskas

Microsoft Lithuania
Microsoft Customer Service and Support (CSS) EMEA

Comments (6)

  1. Tobias says:

    Any chance to handle <enter> in a JavaScript-Addin as well?

  2. KristofVervaeke says:

    Hi,

    I do have a question about this new behavior in CU9 (359667: The Add-in control makes a field not accessible using <enter>.).

    I'm still working with NAV2013R2 build 7. I've created some add-ins and added code to handle the ENTER key.

    Now, with CU9 maybe this behavior has changed.

    Do I have to change my existing add-ins when I upgrade to CU9 (or later) or will they still behave like they do now?

    Thanks.

  3. Gedas B says:

    Hi Kristof

    Yes, most probably you need to redesign your adding by adding code to manage <Enter> key. because after CU9 enter key is left for NAV and used as in normal number field >> confirm field value >> jump to next field.

  4. Kevin Archer says:

    How can this work with a java control addin?

  5. Gheorghe says:

    Hi,

    I am fairly new to Navision, and I am trying to implement this new event handler to a rich text editor. I can see the methods in the assembly if I create a DotNet Object in C/AL Globals, but I am not certain how to “call” the enter key event on my editor.

    I have tried to pass a parameter in the LoadHtml method, which is called when the editor is initialized.

    Editor::ControlAddInReady()
    CurrPage.Editor.LoadHtml(Txt, TRUE);

    and in c#:
    public void LoadHtml(string HTMLData, bool AcceptsEnterKey)
    {
    rtb = new RichTextBox();
    rtb.Multiline =
    }
    This doesn’t work though…How can I implement this functionality ?

    1. Kevin Archer says:

      I’m guessing in java addon this is still not possible, doesn’t make sense

Skip to main content