miltoncwb


Dear Experts,

The previous post was incompleted, sorry.

I am working on a data entry grid with 20 columns, when the user reach the last record and press down arrow, then append blank and move the cursor to column1 of the new record, I put the following code in keypress event :

If nKeycode = 24

select cr_1

appe blank

thisform.grid1.SetFocus
_col = thisform.grid1.ActiveColumn


for a = 1 to _col - 1

keyboard "{leftarrow}"

endfor

endif

_col showing a correct value but the cursor only moved left once, no matter what the current column is!

Any suggestion will be appreciated and thank you for your time.

Milton




Re: keyboard {leftarrow}

Naomi Nosonovsky


If you always want to move cursor to the first column when you added a new record, then this may work

Code Snippet

if m.nKeyCode = 24

if eof() && Or last record

select cr_1

append blank

nodefault

this.parent.parent.column1.SetFocus()

endif

endif






Re: keyboard {leftarrow}

Naomi Nosonovsky

Found also in another forum code by Marcia Akins:

Grid's KeyPress

IF nKeyCode = 24
 WITH This.Parent.Parent
 *** Set Focus elsewhere to avoid Record in use by another error
 *** when we set focus to the first column of the newly appended record
 *** Also, if we do NOT set focus elsewhere, even though the AddNewRecord() method
 *** Does indeed add a new record, the newly appended record appears as the first
 *** line in the grid and the cursor moves to column 1 in the last row of the grid 
  .lAdding = .T.
  .Parent.SetFocus()
  .AddNewRecord()
  .lAdding = .F.
  NODEFAULT
 ENDWITH	
ENDIF	

Code like this in the grid's AddNewRecord method:

LOCAL lcOrder, loColumn
WITH This
 *** First check to see if we have an index order set on the table
 *** because we want add the new record to the bottom of the grid
 *** and not in index order
 lcOrder = ORDER( .RecordSource )
 Thisform.LockScreen = .T.
 SELECT ( .RecordSource )
 SET ORDER TO 
 APPEND BLANK IN ( .RecordSource )
 *** Find out which column is the first column
 FOR EACH loColumn IN .Columns
  IF loColumn.ColumnOrder = 1
   loColumn.SetFocus()
   EXIT
  ENDIF
 ENDFOR
 *** Reset the previous order		
 IF ! EMPTY( lcOrder )
  SET ORDER TO ( lcOrder ) IN ( .RecordSource )
 ENDIF
 .RefreshControls()
 ThisForm.LockScreen = .F.	
ENDWITH	






Re: keyboard {leftarrow}

miltoncwb

Dear Naomi,

I'll try it tomorrow (it is mid night in HK) and drop you a line. Many thanks for your prompt reply!!!

Milton





Re: keyboard {leftarrow}

miltoncwb

Dear Naomi,

It works like this :

If nkeycode = 24

sele cr_1

append blank

nodefault

thisform.refresh

thisform.grid1.column1.setfocus

endif

Many thanks for your generous help!!!

Milton





Re: keyboard {leftarrow}

Naomi Nosonovsky

You're welcome.