Getting the return key to go to the next row in a listbox doesn't work

  1. 4 months ago

    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
  2. Anthony C

    Aug 6 Pre-Release Testers, Xojo Pro, Third Party Store GraffitiSuite Developer
    Edited 4 months ago

    Try this in the CellKeyDown event:

    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
  3. Anthony C

    Aug 6 Pre-Release Testers, Xojo Pro, Third Party Store GraffitiSuite Developer

    And if you want it to work without a cell currently being edited, put this in KeyDown:

    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

    Of course this should be in a method so you don't have the same code in two different places.

  4. @Anthony C Try this in the CellKeyDown event:
    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

    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.

  5. Norman P

    Aug 6 Pre-Release Testers, Xojo Pro under THE bus

    @Matthew J 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 :(

  6. Anthony C

    Aug 6 Pre-Release Testers, Xojo Pro, Third Party Store GraffitiSuite Developer

    Well, that's why he was using Keyboard.AsyncKeyDown, I think. Testing now.

  7. Anthony C

    Aug 6 Pre-Release Testers, Xojo Pro, Third Party Store GraffitiSuite Developer
    Edited 4 months ago

    Here you go, for CellKeyDown:

    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
  8. @Anthony C Well, that's why he was using Keyboard.AsyncKeyDown, I think. Testing now.

    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.

  9. Anthony C

    Aug 6 Pre-Release Testers, Xojo Pro, Third Party Store GraffitiSuite Developer

    Happy to help!

  10. Norman P

    Aug 6 Pre-Release Testers, Xojo Pro under THE bus

    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

or Sign Up to reply!