|
Advanced PowerBuilder TAB Key Behavior to the ENTER Key in a DataWindow
By default, pressing the ENTER key changes the focus to the same column in row below it, if there is any row below it. In a typical data-entry screen in the industry, pressing the ENTER moves the focus to the next field in the same row. Let's now add this functionality to the DataWindow. Declare a user-defined event ue_ProcessEnter and map pbm_dwnProcessEnter event id to it and write the following code:
// Object: dw_product
// Event: Ue_ProcessEnter
long ll_CurrentRow
int li_ColCount, li_ColNo
int i, li_TabOrder, li_Protection
boolean lb_IsColumnSet
li_ColCount = integer(this.object.DataWindow.Column.Count )
li_ColNo = this.GetColumn()
IF li_ColNo < li_ColCount THEN
this.SetColumn( li_ColNo + 1 )
FOR i = ( li_ColNo + 1 ) TO li_ColCount
li_TabOrder = &
integer( this.Describe( "#" + String(i) + &
".TabSequence" ))
li_Protection = &
integer( this.Describe( "#" + String(i) + &
".Protect" ))
IF li_TabOrder > 0 AND li_Protection = 0 THEN
this.SetColumn( i )
lb_IsColumnSet = TRUE
EXIT
END IF
NEXT
END IF
// No non-protected, non-zero tab order column found.
IF NOT lb_IsColumnSet THEN
ll_CurrentRow = this.GetRow()
// Let's try in the next row, if there is one.
if ll_CurrentRow = this.RowCount() THEN return 1
// There is a row.
FOR i = 1 TO li_ColCount
li_TabOrder = &
integer( this.Describe( "#" + String(i) + &
".TabSequence" ))
li_Protection = &
integer( this.Describe( "#" + String(i) + &
".Protect" ))
IF li_TabOrder > 0 AND li_Protection = 0 THEN
// Column is found. Let's set the focus and
// scroll to that row.
this.SetRow( ll_CurrentRow + 1 )
this.SetColumn( i )
this.ScrollToRow( ll_CurrentRow )
EXIT
END IF
NEXT
END IF |
The first IF condition in the above code sets the focus to the next non-protected, non-zero tab order field, if available. Otherwise, it tries to set on the next row (if next row is there). If none of them is true, then this code does nothing.
|