Highlighted
Absent Member.
Absent Member.
722 views

How do I know where I am when traversing form content??

Jump to solution

Using the <RET> key to traverse through a form with a number of fields what question can I ask to determine WHICH field I've just pressed the <RET> key on?

Have tried using the TabIndex property like:

if self::TabIndex = 0
    invoke self::processEmployeeNumber()
    exit method
end-if

for asking if  I'm on the first field on the form but it doesn't seem to work as it appears that this code is processed even WHEN I'm on the 10th field (tabindex property = 9).

So I know I've pressed the <RET> key so how do I now know on WHICH field I've pressed it on?

 

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: How do I know where I am when traversing form content??

Jump to solution

The following code should work for you.
I have created a new method called GetFocusedControl which is called in the Keydown method.

This will return null if no control has focus or will contain the control that has focus.

This control can then be tested with an evaluate statement.

      method-id Form1_KeyDown final private.
      01 mycontrol type Control.
      procedure division using by value sender as object e as type System.Windows.Forms.KeyEventArgs.
             set mycontrol to self::GetFocusedControl(self::Controls)
             evaluate mycontrol
                when self::textBox1
                   invoke type MessageBox::Show("textBox1 active")
                when self::textBox2
                   invoke type MessageBox::Show("textBox2 active")
                when self::dataGridView1
                   invoke type MessageBox::Show("datagrid active")
                when null
                   invoke type MessageBox::Show("no control is focused")
             end-evaluate
             set e::Handled to true
      end method.

      method-id GetFocusedControl public.
      01 container type ContainerControl.
      procedure division using controlsin as type Control+ControlCollection
                         returning mycontrol as type System.Windows.Forms.Control.
          perform varying clsControl as type System.Windows.Forms.Control thru self::Controls
             if clsControl::Focused
                set mycontrol to clsControl
                goback
             else
                if clsControl::ContainsFocus
                   if clsControl::Controls::Count = 0
                      set mycontrol to clsControl
                      goback
                   else
                      set mycontrol to self::GetFocusedControl(clsControl::Controls)
                      goback
                   end-if
                end-if
             end-if
          end-perform
          set mycontrol to null
          goback.
      end method.

View solution in original post

0 Likes
1 Reply
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: How do I know where I am when traversing form content??

Jump to solution

The following code should work for you.
I have created a new method called GetFocusedControl which is called in the Keydown method.

This will return null if no control has focus or will contain the control that has focus.

This control can then be tested with an evaluate statement.

      method-id Form1_KeyDown final private.
      01 mycontrol type Control.
      procedure division using by value sender as object e as type System.Windows.Forms.KeyEventArgs.
             set mycontrol to self::GetFocusedControl(self::Controls)
             evaluate mycontrol
                when self::textBox1
                   invoke type MessageBox::Show("textBox1 active")
                when self::textBox2
                   invoke type MessageBox::Show("textBox2 active")
                when self::dataGridView1
                   invoke type MessageBox::Show("datagrid active")
                when null
                   invoke type MessageBox::Show("no control is focused")
             end-evaluate
             set e::Handled to true
      end method.

      method-id GetFocusedControl public.
      01 container type ContainerControl.
      procedure division using controlsin as type Control+ControlCollection
                         returning mycontrol as type System.Windows.Forms.Control.
          perform varying clsControl as type System.Windows.Forms.Control thru self::Controls
             if clsControl::Focused
                set mycontrol to clsControl
                goback
             else
                if clsControl::ContainsFocus
                   if clsControl::Controls::Count = 0
                      set mycontrol to clsControl
                      goback
                   else
                      set mycontrol to self::GetFocusedControl(clsControl::Controls)
                      goback
                   end-if
                end-if
             end-if
          end-perform
          set mycontrol to null
          goback.
      end method.

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.