Setting SelLength in a Listbox

In a ListBox, I have programmed CellKeyDown so that the arrow keys and tab key allow one to move between cells in any direction.

When a cell is selected, either by keyboard or mouse click, the system selects all of the data in the cell, and if one accidentally presses a key, that data is gone, replaced by the character that was pressed.

To avoid the accidental trashing of data in any cell of the ListBox, I am trying to set the SelLength of each cell to 0 on selection.

lbAllDat.ActiveCell.SelLength=0. Works if placed in a button.

me.ActiveCell.SelLength=0 placed in the CellGotFocus event, compiles, but does not execute when
running the application.

Where do I place “me.ActiveCell.SelLength=0” to have it execute on opening a cell?

Thanks, -Will

I would place it (not tested !) in the gotfocus event of the textarea that is the activecell.
this should imply the use of addhandler and removehandler methods.

@William Bonney – Actually CellGotFocus is called, but for some reason modifications to ActiveCell do nothing, even when forcing Refresh.

To work around this, I created a Timer with a period of 0. From the CellGotFocus event, I start the Timer which, in turn, set the SelLength of the ActiveCell. And it works.

Thanks Stphane! That worked great!

About the reasons:
While you are inside the CellGotFocus Event, you cannot change the cell’s selection because the cell content is not yet selected. This follows in the event chain after an editable cell got its focus, therefore the system overrides happily whatever you did in between.
In many cases where you want to modify a control from inside an event, it is best practice to use a timer (or Xojo.core.timer.CallLater call) so the system has at least one round through its main event loop to process following events.