Auto advance in listbox?

I have a listbox that the user enters values (amounts) in one of the cells and what I want to happen is for the listbox to advance to the next row and same cell as they hit the enter or return key.

I’ve tried putting the following code in the “celllostfocus” and the “cellkeydown” and the listbox’s keydown but nothing seems to work.

celllostfocus:

me.editcell(row+1,column)

cellkeydown:

if key = cur(13) or key = chr(3) then
me.editcell(row+1,column)
end

listbox’s keydown: (nRow and nColumn are set by the cellgotfocus)

if key = cur(13) or key = chr(3) then
listbox.editcell(nRow+1,nRowcolumn)
end

The behavior I’m getting is when I press the enter or return key, the value enter in the cell is saved, but no advance.

Any help appreciated and I didn’t see this addressed anywhere in the forums.

Thanks

I made a little progress, I can now get the row to advance by putting the following code in the cellkeydown:

if (Column = 2 or Column = 3) and Row + 1 < me.ListCount then
if AscB(key) = 13 or AscB(key) = 3 then
nRow = nRow + 1
me.EditCell(nRow,Column)
end
end

But the me.EditCell(nRow,Column) does not put me in edit mode for the cell. nRow is a variable set in cellgotfocus.

What am I doing wrong?

Here is the best I’ve been able to come up with. Might be of use to someone else:

I added this code to the listbox.keydown

This listbox has 4 columns: AC, ACName, Debit, Credit

The user will be entering debit and credit balances for each account.

It appears that when you are editing a cell XOJO and you press the ENTER / RETURN key that terminates the edit but you can’t use the listbox.editcell to immediately tell it to edit another cell. I have that line of code marked in the code fragment below.

I trap for the last key so if they moved the row up or down, I don’t want to advance to another row or immediately edit the cell.

Anyone got a fix for this or is that just the way it is?

'----------------------------------------------- listbox.keydown
dim nReturn As Boolean

if nRow < me.ListCount then

'---  DOWN ARROW, RETURN KEY, ENTER KEY
if AscB(key) = 13 or AscB(key) = 3 then
  
  '--- LAST KEY WAS NOT UP ARROW OR DOWN ARROW -  MOVE DOWN ONE ROW
  if nLastkey <> 30 AND nLastkey <> 31 then
    me.ListIndex = nRow + 1
   
   '---  THIS DOES NOT WORK!!!
    me.EditCell(nRow+1,Column)

  end
        
  nReturn = True
  
end

end

'— LEFT ARROW - MOVE TO DEBIT COLUMN
if AscB(key) = 28 then

me.EditCell(nRow,2)

nReturn = True

'---  RIGHT ARROW - MOVE TO CREDIT COLUMN

elseif AscB(key) = 29 then
me.EditCell(nRow,3)

nReturn = True

end

nLastkey = AscB(key)

Return nReturn

It’s been a while, but I think I had to clear the focus before I could start the next edit. Try

me.SetFocus
me.EditCell(nrow+1,Column)

Tim

Thanks for the reply. No, that didn’t work, but thanks for the idea. Any others?

If you start a new project and throw a listbox on the window, this code in the CellKeyDown event moves down the column.

  if key = chr(13) then
    me.EditCell(row+1, column)
    return true
  end

Note that without the return true it doesn’t work.