Activating edit mode in a list box cell

The way I read the docs, if you want to edit a cell in a list box, you need to use the EditCell method to set it to edit mode.

Me.EditCell(row, column)

But, I’m finding that if I click on an editable cell once, pause for an instant and click again, the cell becomes editable without me having to use the EditCell method.

It is behaving similar to the way a file name in the Finder gets activated for rename when selected and then selected again after pausing for an instant.

This is on MacOS using latest version of XOJO. I don’t see anything in the docs saying this is how it works. It came up because I was going to use Keyboard.Shiftkey to activate edit mode for the cell, but found that it would go into edit mode whether or not the shift key was pressed. I created a new project with a listbox that does not invoke EditCell and cells do become active for edit when clicked the way I describe.

Should I rely on this behavior or use belt and suspenders and tell my users to press the shift key and click to set a cell in edit mode?

You can override the “click a selected cell to edit” feature and only allow edits using shift+click by putting the following code in your ListBox.CellClick event:

Function CellClick(row as Integer, column as Integer, x as Integer, y as Integer) Handles CellClick as Boolean Me.Selected(row) = True If Keyboard.AsyncShiftKey Then Me.EditCell(row, column) End If Return True End Function

Apologies if you knew this already and I didn’t answer what you asked :slight_smile:

As for “is that the right thing to do” is another matter as I’m not sure that is standard on any platform (as it’s F2 on windows and the click to edit is left in) but if its clearly labelled for your app then I guess its ok :slight_smile:

I had not noticed the CellClick event, which I agree is a better place to handle the EditCell method. But, the issue is that the cell can be made editable without using EditCell. I just tried this on Windows 10 and it works the same way there. Your code, which is similar to the way I was handling this, is superfluous unless you include setting the celltype to editable in the same if statement where you check for the shift key, No?

Listbox.EditCell in code will let you edit any cell regardless of what type you set it to… So if you don’t want the user to be able to edit by clicking on it, just don’t set teh cell type to editable then you can simply control when you want it to be editable.

  • karen

Aha! Thank you. I was under the impression that a cell had to be set as editable in order to edit. Now it makes sense.