·
3 min read

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