1. mathews rutto
  2. PowerBuilder
  3. Tuesday, 17 September 2024 14:12 PM UTC

Hi,

How do you implement the enter key on a datawindow.

I have a button in a data object window, I need to press enter to execute the triggered clicked event of the button.

with kind regards

John Fauss Accepted Answer Pending Moderation
  1. Wednesday, 18 September 2024 14:22 PM UTC
  2. PowerBuilder
  3. # 1

Here is the revised example app. The Q&A editor does not appear to allow an attachment to be replaced...only deleted.

The ue_ProcessEnter event script:

// ue_ProcessEnter event (mapped to pbm_dwnprocessenter)

// PB triggers this DW event when a column has input focus and the Enter key has been pressed.
// This script triggers the ButtonClicked event for a button DWObject when Enter is pressed.

Long     ll_row, ll_action
String   ls_button_name
DWObject ldwo

// In order to trigger the ButtonClicked event for a button DWObject,
// you must supply three argument values:
//  1. The row number (long).
//  2. A code designating the action to be taken when the button is clicked (long).
//     Refer to this property of the button DWObject in the DataWindow Painter for
//     more information on the possible values of this code.
//  3. A reference to the button DWObject that has been clicked.

ll_row = This.GetRow()
If ll_row < 1 Or ll_row > This.RowCount() Then Return 0

ll_action = 0   // 0 => User Defined action

// If you can hard-code the name of the button DWObject, you can obtain a reference
// to it via dot notation. In this example, the button DWObject's name is "b_click_me".
ldwo = This.Object.b_click_me

// If you cannot hard-code the name of the button DWObject, you can dynamically obtain
// a reference to it via the undocumented __get_attribute method, as shown below:
//ls_button_name = "b_click_me"  // ...for example
//ldwo = This.Object.__get_attribute(ls_button_name,False)

// Trigger the ButtonClicked event, but only if we have a valid DWObject reference.
If IsValid(ldwo) Then
   This.Event ButtonClicked(ll_row,ll_action,ldwo)
   
   // If desired, post a call to the SetRow() method to keep the same current row
   // after the Enter key is pressed, as shown below.
   This.Post Function SetRow(ll_row)
End If

Return 0
Comment
  1. Chris Pollach @Appeon
  2. Wednesday, 18 September 2024 14:39 PM UTC
Thanks John! :-)
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Tuesday, 17 September 2024 18:42 PM UTC
  2. PowerBuilder
  3. # 2

There's a special event for the enter key: pbm_processenter.

Comment
  1. John Fauss
  2. Tuesday, 17 September 2024 19:58 PM UTC
Correction: The mapped event ID is pbm_dwnprocessenter, not pbm_processenter.
  1. Helpful 1
  1. Miguel Leeuwe
  2. Wednesday, 18 September 2024 13:02 PM UTC
Sorry, John is correct. It should be pbm_dwnprocessenter.
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 17 September 2024 18:34 PM UTC
  2. PowerBuilder
  3. # 3

Attached is a very simple, single-window PB app developed in PB 2017 R2 that works in versions up through 2022 R3 Build 3391. It uses the code I provided in my earlier post.

* * * Updated * * *

I have revised and replaced the example app to use the pbm_dwnprocessenter event suggested by Miguel and to use dot notation to obtain a reference to the button DWObject instead of using the undocumented __get_attribute function. I have kept (commented) code showing how the __get_attribute function can be used in cases where you cannot hard-code the name of the DWObject that you need to obtain a reference to.

Thanks and a hat tip to Miguel and Arnd for helping me find a better solution for Mathews' issue!

Comment
  1. Chris Pollach @Appeon
  2. Wednesday, 18 September 2024 14:25 PM UTC
Hmmm .. what attachment?
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 17 September 2024 15:01 PM UTC
  2. PowerBuilder
  3. # 4

Hi, Mathews -

It's a little tricky, but only because in order to trigger the DW's ButtonClicked event, you need a reference to the button DWObject. However, there is an undocumented way to obtain a reference to a DWObject if you know its name:

// Create a user event in the DataWindowControl that is mapped to pbm_dwnkey,
// call it "ue_keydown". Place the following code in this user event.

DWObject ldwo
Long     ll_row, ll_actioncode

// Ignore all keystrokes other than the Enter key.
If key <> KeyEnter! Then Return 0

// Prepare the arguments for the DWC's ButtonClicked event:
ll_row        = This.GetRow()
ll_actioncode = 0             // UserDefined (default) - Change if necessary.
// Use undocumented method to obtain a reference to the Button DWObject in the DW.
// In this example, the Button DWObject's name is "b_1".
ldwo          = This.Object.__get_attribute('b_1',False)

// Trigger the ButtonClicked event, but only if we have a valid DWObject reference.
If IsValid(ldwo) Then
   This.Event ButtonClicked(ll_row,ll_actioncode,ldwo)
End If

Return 0

Best regards, John

Comment
  1. John Fauss
  2. Tuesday, 17 September 2024 15:58 PM UTC
I successfully tested the code in PB 2019 R3 prior to posting it, and I've used it in several earlier versions of PB, but I have not tested it in more recent versions. Make sure you have the name of that method specified correctly... the name begins with TWO underscores. It is also critical that the user event be mapped to event ID pbm_dwnkey, NOT pbm_keydown.

If I had known what version of PB you are using, I might have been able to test using the same. This is why you should ALWAYS state the version, release and build number of your PB environment whenever you ask a question.
  1. Helpful
  1. mathews rutto
  2. Tuesday, 17 September 2024 19:05 PM UTC
The version i am using is Powerbuider 2023 r3 3289
  1. Helpful
  1. mathews rutto
  2. Tuesday, 17 September 2024 19:06 PM UTC
The version i am using is Powerbuider 2022 r3 3289
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.