CellFocusReceived modifiy text for editable cell


I want to remove some characters on a cell before editing

on the double-click event of the DesktopListbox, I call the following code


The cell contains for example 2%

I want the editable cell to be showing only 2 and not the % sign

So I use the CellFocusReceived to try to remove the %

if me.CellTextAt(row,column).Right(1) = "%" then
  me.CellTextAt(row,column) = me.CellTextAt(row,column).Left(me.CellTextAt(row,column).Length-1)
end if

But the result is that it highlights only the 2 and let the % inside the cell


Is there a way to do it and remove the % when editing?

On the CellAction event, I check that the input is valid by calling IsNumeric

On the CellFocusLost event I have a similar code to append the % sign to the number and it works well.

if me.CellTextAt(row,column).Right(1) <> "%"  then
  me.CellTextAt(row,column) = me.CellTextAt(row,column) + "%"
end if

I am on Xojo 2022r2 (macOS 11.5)

Thank you,


Here’s how I do it for currency values. Note I keep the currency value in the celltag.

Sub CellFocusReceived(row as Integer, column as Integer) Handles CellFocusReceived
  Var Price As Currency = me.CellTagAt(row, column)
  Me.CellTextAt(row, column) = Price.ToString(Nil)
End Sub
Sub CellAction(row As Integer, column As Integer) Handles CellAction
  Var Price As Currency = Currency.FromString("0" + me.CellTextAt(row, column))
  me.CellTextAt(row, column) = Price.ToString(locale.Current)
  me.CellTagAt(row, column) = Price
End Sub

I do the same thing as you are doing (storing the value in the celltag) but something must be wrong with my code as it just highlight the character when editing

Set a breakpoint in the method that adds the “%”. I bet it gets reached after you removed the “%”.