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
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
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
There's a special event for the enter key: pbm_processenter.
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!
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