Have you ever needed to implement a key search capability in a
DataWindow, where the user could type a key and the appropriate
row would scroll into view? If so this tip may help.
The secret is the ASCII value of the key pressed is stored in
the Message objects WordParm property in the key events. By
capturing this value and coverting it to its character
representation, we can search a specified column and scroll to
the row if it is found.
Declare a user event ue_keyup for the system event pbm_keyup
and add the following code:
// Key Search: Scrolls to row based on key pressed by searching the column specified.
// Searches for following key presses (A-Z, 0-9)
long ll_row
integer li_key, li_temp, li_pos
string ls_column, ls_temp
// Get ASCII Value of Key Pressed
li_key = Message.WordParm
// Get Specified Column
// DW should be sorted on this column so jumps make sense
// In this case we get the first column in the Sort Order
ls_temp = this.Describe("DataWindow.Table.Sort")
li_pos = Pos(ls_temp, ",")
li_temp = Pos(ls_temp, " A")
IF (li_temp = 0 ) OR (li_temp > li_pos) THEN
li_temp = Pos(ls_temp, " D")
END IF
ls_column = Left(ls_temp, li_temp -1)
// Make sure letter is A-Z, a-z, 0-9
IF ((li_key > 64) AND (li_key < 91)) OR &
((li_key > 47) AND (li_key < 58)) THEN
// If user already hit this key
// move to next row with same letter
IF li_key=ii_last_key THEN
ll_row=this.GetRow() + 1
ELSE
ll_row=1
END IF
ls_temp="ASC(UPPER(LEFT(" + ls_column + ",1)))>= " + String(li_key)
ll_row = this.Find(ls_temp, ll_row, this.RowCount())
IF ll_row > 0 THEN
this.ScrollToRow(ll_row)
this.SetRow(ll_row)
END IF
ii_last_key = li_key
END IF
|