Create editable listbox

Hi group, I would like to have an editable listBox … insert values ​​and archive them … I have been reading a few guides but I can’t, also because sometimes I don’t understand the concept in English. Do you have an example or could you tell me if there is a simple way to do this? Otherwise I always have to go through the textfiled first and then archive the data and display it in the listbox.

https://documentation.xojo.com/api/user_interface/desktop/desktoplistbox.html#desktoplistbox-editcellat

You want to set the ColumnType in the opening event of the listbox. So if you want to be able type in the second column, you’d add the following code to the listbox’s Opening Event. (Counting starts at zero)

me.ColumnTypeAt(1) = DesktopListBox.CellTypes.TextField

Tabbing is not automatic, so the listbox CellKeyDown can be used to move the cursor around:

Function CellKeyDown(row as Integer, column as Integer, key as String) Handles CellKeyDown as Boolean
If Keyboard.AsyncKeyDown(&h30) Then ' tab key typed 
  Select Case True
  Case Keyboard.AsyncShiftKey And column>0
    Me.EditCellAt(row,column-1)
    
  Case Keyboard.AsyncShiftKey And column=0 And row>0
    Me.EditCellAt(row-1,Me.LastColumnIndex)
    
  Case Keyboard.AsyncShiftKey And column=0 And row=0
    Me.EditCellAt(Me.LastAddedRowIndex,Me.LastColumnIndex)
    
  Case Me.LastColumnIndex>column
    Me.EditCellAt(row,column+1)
    
  Case Me.LastColumnIndex=column And Me.LastRowIndex>row
    Me.EditCellAt(row+1,0)
    
  Case Me.LastColumnIndex=column And Me.LastRowIndex=row
    Me.EditCellAt(0,0)
    
  End Select
End If
  
End Function

Thanks group, I will study and try.

Hey Keith,

Nice to see you here!

Sorry, didn’t mean to hijack the thread.

JOhn…

Hello John,

Nice to see you here too. Still getting used to not typing the semi-colon!

Keith

1 Like

Hey Keith,

I here ya!

A whole new world is before us!

Enjoy,
John…

Is there a recommended way to suppress the row selection highlight in a listbox? The effect would allow tabbing around inside the enterable listbox without the entire row highlighting. Only the cell would have the focus ring.

The PaintCellBackground event looks like a possible path, but the way I’m using it in the example project makes the columns adjacent to the focus cell appear empty.

macOS 15.3.2, Xojo 2025R1

EnterableListbox.zip (8.6 KB)

In the CellFocusReceived event add this line to the end:

me.SelectedRowIndex = -1

While you’re editing the cell the row won’t be highlighted, and the same for tabbing to the next cell. But when you hit return/enter, the row will be highlighted again.

That works great!

That idea never comes to my mind. In fact, I take that as a User Report: you are editing that Row.
And I add a Green Rectangle to inform the user (s)he is in Edit Mode, after I read this thread.

Of course, it is a matter of taste.

Here is a version of the enterable listbox with the suggestions incorporated.
EnterableListbox.zip (8.4 KB)

Thanks Keith !!!