I can get arrow keys to navigate up and down, but the return key doesnt seem to be working. I’v tried key codes 13 and 24 for the return key with no luck.
Here is my code:
if Keyboard.AsyncKeyDown(126) then // up key
if row <= (me.ListCount-1) and row > 0 then
Me.EditCell(row-1, column)
Me.activecell.selectAll
end if
elseif Keyboard.AsyncKeyDown(125) or Keyboard.AsyncKeyDown(24) then // down key
if row < (me.ListCount-1) and row >= 0 then
Me.EditCell(row+1, column)
Me.activecell.selectAll
end if
end if
Try this in the CellKeyDown event:
[code]select case Asc(key)
case 126 // up key
if row <= (me.ListCount-1) and row > 0 then
Me.EditCell(row-1, column)
Me.activecell.selectAll
end if
case 125, 13, 3 // down key or enter
if row < (me.ListCount-1) and row >= 0 then
Me.EditCell(row+1, column)
Me.activecell.selectAll
Return True
end if
end select[/code]
And if you want it to work without a cell currently being edited, put this in KeyDown:
[code]dim row as Integer = me.ListIndex
dim column as Integer = 0
select case Asc(key)
case 126 // up key
if row <= (me.ListCount-1) and row > 0 then
Me.EditCell(row-1, column)
Me.activecell.selectAll
end if
case 125, 13, 3 // down key or enter
if row < (me.ListCount-1) and row >= 0 then
me.ListIndex = row + 1
Me.EditCell(row+1, column)
Me.activecell.selectAll
Return True
end if
end select[/code]
Of course this should be in a method so you don’t have the same code in two different places.
[quote=449251:@Anthony Cyphers]Try this in the CellKeyDown event:
[code]select case Asc(key)
case 126 // up key
if row <= (me.ListCount-1) and row > 0 then
Me.EditCell(row-1, column)
Me.activecell.selectAll
end if
case 125, 13, 3 // down key or enter
if row < (me.ListCount-1) and row >= 0 then
Me.EditCell(row+1, column)
Me.activecell.selectAll
Return True
end if
end select[/code][/quote]
Thanks for the response. The return key does function now to go to the next row, but the arrow keys no longer work. The arrow keys now just navigate in the text in the cell.
once you have a cell in edit mode the cell takes over handling those key strokes
and there’s nothing you can do to override that
Well, that’s why he was using Keyboard.AsyncKeyDown, I think. Testing now.
Here you go, for CellKeyDown:
[code]select case Asc(key)
case 13, 3 // Enter or Return
if row < (me.ListCount-1) and row >= 0 then
Me.EditCell(row+1, column)
Me.activecell.selectAll
Return True
end if
end select
if Keyboard.AsyncKeyDown(126) then '// Up key
if row <= (me.ListCount-1) and row > 0 then
Me.EditCell(row-1, column)
Me.activecell.selectAll
Return True
end if
elseif Keyboard.AsyncKeyDown(125) then '// Down key
if row < (me.ListCount-1) and row >= 0 then
Me.EditCell(row+1, column)
Me.activecell.selectAll
Return True
end if
end if[/code]
I think I may be on to something. I use your code to use return to go to the next cell and my previous code to keep the arrow keys working. Thank you for all the help so far.
In cellkeydown this seems to work as well
If key = &u1E Then
If row <= (Me.ListCount-1) And row > 0 Then
Me.EditCell(row-1, column)
Me.activecell.selectAll
End If
Elseif key = &u1D Then
If row < (Me.ListCount-1) And row >= 0 Then
Me.EditCell(row+1, column)
Me.activecell.selectAll
End If
End If