Skip to main content

In my program, I am using an Enter Key to work the same as a Tab key, from what I have read on the Internet, it tells me to use the MoveFocus

In C#, the command is this:  new TraversalRequest(FocusNavigationDirection.Next))

SO I tried with the highlighted code below, but I can't get it to recognize the Next.  I know I have this written wrong -what is the correct way to write this?

(I am using WPF for my screens)

       entry "WPR_AP110000_F_DUE_DATE_KEYDOWN" using by value sender e_key.
           PERFORM SET-LINKAGE.
       AP110000-F-DUE-DATE-KEYDOWN.
           move e_key::Key to WOW-KEY-VALUE.
           MOVE WOW-KEY-VALUE TO WIN-KEY.

           IF WIN-KEY = type Key::Return
               Invoke AP110000_WIN::F_DUE_DATE::MoveFocus(new TraversalRequest(new FocusNavigationDirection()))
           END-IF.

In my program, I am using an Enter Key to work the same as a Tab key, from what I have read on the Internet, it tells me to use the MoveFocus

In C#, the command is this:  new TraversalRequest(FocusNavigationDirection.Next))

SO I tried with the highlighted code below, but I can't get it to recognize the Next.  I know I have this written wrong -what is the correct way to write this?

(I am using WPF for my screens)

       entry "WPR_AP110000_F_DUE_DATE_KEYDOWN" using by value sender e_key.
           PERFORM SET-LINKAGE.
       AP110000-F-DUE-DATE-KEYDOWN.
           move e_key::Key to WOW-KEY-VALUE.
           MOVE WOW-KEY-VALUE TO WIN-KEY.

           IF WIN-KEY = type Key::Return
               Invoke AP110000_WIN::F_DUE_DATE::MoveFocus(new TraversalRequest(new FocusNavigationDirection()))
           END-IF.

Try:
invoke AP110000_WIN::F_DUE_DATE::MoveFocus(new type TraversalRequest(type FocusNavigationDirection::Next))


Try:
invoke AP110000_WIN::F_DUE_DATE::MoveFocus(new type TraversalRequest(type FocusNavigationDirection::Next))

For some reason, this code is not working with a DatePicker Field (I tested it on another text box field in my code, and it advanced correctly, so the code is correct.)

Got any Ideas on what to do on a DatePicker field.


For some reason, this code is not working with a DatePicker Field (I tested it on another text box field in my code, and it advanced correctly, so the code is correct.)

Got any Ideas on what to do on a DatePicker field.

I did some searching and found the following code to work for all controls on a window so you dont have to individually create event handlers for each control. In my test this also worked on a DatePicker control. This will work if your controls are laid out on a Grid.

In the App.xaml.cbl program add the following 2 methods:

       method-id OnStartup protected override.
       procedure division using by value e as type StartupEventArgs.
           
           invoke type EventManager::RegisterClassHandler((type of type UIElement), type UIElement::PreviewKeyDownEvent, new type KeyEventHandler(Grid_PreviewKeyDown))
           invoke super::OnStartup(e)

       end method.
       method-id Grid_PreviewKeyDown private.
       procedure division using by value sender as object, e as type System.Windows.Input.KeyEventArgs.
 
          declare uie = e::OriginalSource as type UIElement
          if e::Key = type Key::Enter
             set e::Handled = true
             invoke uie::MoveFocus(new TraversalRequest(type FocusNavigationDirection::Next))
          end-if
       end method.


I did some searching and found the following code to work for all controls on a window so you dont have to individually create event handlers for each control. In my test this also worked on a DatePicker control. This will work if your controls are laid out on a Grid.

In the App.xaml.cbl program add the following 2 methods:

       method-id OnStartup protected override.
       procedure division using by value e as type StartupEventArgs.
           
           invoke type EventManager::RegisterClassHandler((type of type UIElement), type UIElement::PreviewKeyDownEvent, new type KeyEventHandler(Grid_PreviewKeyDown))
           invoke super::OnStartup(e)

       end method.
       method-id Grid_PreviewKeyDown private.
       procedure division using by value sender as object, e as type System.Windows.Input.KeyEventArgs.
 
          declare uie = e::OriginalSource as type UIElement
          if e::Key = type Key::Enter
             set e::Handled = true
             invoke uie::MoveFocus(new TraversalRequest(type FocusNavigationDirection::Next))
          end-if
       end method.

Well - that worked, BUT now everytime I press enter ANYWHERE in the software, it moves to the next field, which is not the way our screens process.

So I can't use this - I need to only be able to do it on this one field...


Well - that worked, BUT now everytime I press enter ANYWHERE in the software, it moves to the next field, which is not the way our screens process.

So I can't use this - I need to only be able to do it on this one field...

I finally got this to work by using the following code in the KeyDown event handler for the control.

       method-id DatePick1_KeyDown.
       procedure division using by value sender as object e as type System.Windows.Input.KeyEventArgs.

            *> Creating a FocusNavigationDirection object and setting it to a
            *> local field that contains the direction selected.
           declare focusDirection as type FocusNavigationDirection  = type FocusNavigationDirection::Next

            *> MoveFocus takes a TraveralReqest as its argument.
           declare request as type TraversalRequest = new TraversalRequest(focusDirection)

            *> Gets the element with keyboard focus.
           declare elementWithFocus as type UIElement  = type Keyboard::FocusedElement as type UIElement

           *> Change keyboard focus.
           if elementWithFocus not = null
              if elementWithFocus::MoveFocus(request)
                  set e::Handled = true
              end-if
           end-if
      
       end method.


I finally got this to work by using the following code in the KeyDown event handler for the control.

       method-id DatePick1_KeyDown.
       procedure division using by value sender as object e as type System.Windows.Input.KeyEventArgs.

            *> Creating a FocusNavigationDirection object and setting it to a
            *> local field that contains the direction selected.
           declare focusDirection as type FocusNavigationDirection  = type FocusNavigationDirection::Next

            *> MoveFocus takes a TraveralReqest as its argument.
           declare request as type TraversalRequest = new TraversalRequest(focusDirection)

            *> Gets the element with keyboard focus.
           declare elementWithFocus as type UIElement  = type Keyboard::FocusedElement as type UIElement

           *> Change keyboard focus.
           if elementWithFocus not = null
              if elementWithFocus::MoveFocus(request)
                  set e::Handled = true
              end-if
           end-if
      
       end method.

That did it!! Thank you so much for your help!! I really appreciate it 🙂