« Make a 32-bit FileMak… | Home | SQLite in memory data… »

Handling tab in Listbox

If you use the Xojo (or Real Studio or REALbasic) Listbox control and you have editable cells, you may want to use the tab key to move inside the listbox.

The code below helps here. I use it in several projects and normally customise it heavily. For example you could add cursor keys to it or other keys beside tab key.
You call it from CellKeyDown event like this:

EventHandler Function CellKeyDown(row as Integer, column as Integer, key as String) As Boolean if HandleTabInList(me, row, column, key) then Return true End EventHandler

Here is the HandleTabInList method which you may want to copy to a module:

Function HandleTabInList(list as listbox, row as integer, column as integer, key as String) As Boolean // Handle tab character in Listbox.CellKeyDown event Select case asc(key) case 9 if Keyboard.AsyncShiftKey then // back // look for column left for i as integer = column-1 downto 0 if list.ColumnType(i) >= list.TypeEditable then list.EditCell(row, i) Return true end if next // not found, so look in row before row = row - 1 if row >= 0 then for i as integer = list.ColumnCount-1 downto 0 if list.ColumnType(i) >= list.TypeEditable then list.EditCell(row, i) Return true end if next end if else // forward // look for column right for i as integer = column+1 to list.ColumnCount-1 if list.ColumnType(i) >= list.TypeEditable then list.EditCell(row, i) Return true end if next // not found, so look in row below row = row + 1 if row < list.ListCount then for i as integer = 0 to list.ColumnCount-1 if list.ColumnType(i) >= list.TypeEditable then list.EditCell(row, i) Return true end if next end if end if end Select End Function

As you see in the code, we handle tab and shift + tab for moving back and forward. Also we wrap to previous/next row if needed. Feel free to extend this to wrap from last to first row or create a new row for editing.
10 06 15 - 13:45