Format cell in listbox as currency

I have a listbox that has 7 columns. Column 4 is loaded from a query with a formatted currency value. This column/cell can be edited by the user to change that value, but I can’t seem to figure out how to automatically format the new value as currency (in other words, assign the $ to the beginning of the new value and if there is no decimal automatically assign .00 as the suffix.)

I found an old reference from 2015 but when I read the documentation I don’t see the Properties or Methods available that are referenced in the answer.

One other “issue” is that when a user makes a change ( there are three columns/cells that are set for editing ) they have to press the Enter/Return key twice to save the change and fire update code that takes the new value and performs a simple calculation. Why won’t it work with a single key press?

In the previous API, I used:
ListBox.ActiveCell.Mask

https://documentation.xojo.com/api/deprecated/listbox.html#listbox-activetextcontrol

For API2, look at TextEdit, Mask
https://documentation.xojo.com/api/deprecated/textedit.html

https://documentation.xojo.com/api/deprecated/textedit.html.Validationask

Without your actual code, how can we give anything other than guesses or bets ?

lstBxOrders.KeyDown

Var strQty As String  = Me.CellValueAt( Me.SelectedRowIndex, 3 ) // This should catch the qty changes...
Var A As Integer = strQty.ToInteger // Converts quantity to Integer Value...
Var intLineCnt As Integer = Me.CellValueAt(Me.SelectedRowIndex, 0 ).ToInteger // Line Count... Line number for item in order que
Var strItemNomen As String = Me.CellValueAt( Me.SelectedRowIndex, 2 ).ToText // Product Name/Nomenclature...
Var strDiscount As String=  Me.CellValueAt( Me.SelectedRowIndex, 5 ).ToText // Discount...
Var strSellPrice As String = "$" + Me.CellValueAt( Me.SelectedRowIndex, 4 ).ToText // Sell Price...
Var curSellPrice As Currency

Var intRun As Integer

Var strCustId As String = ""
Var strSaleId As String = lblDisplaySaleId.Value.ToText
Var intItemQty As Integer = A
Var strLineItemCode As String = ""
Var strSaleState As String = "Active"

' Function(s) / Logic...
Select Case ASCB( key )
Case 13 // RETURN KEY
  intRun = 1
  'Return False
  
Case 3 // ENTER KEY
  intRun = 1
  'Return False
  
End Select

Select Case intRun
Case 1
  If( strSellPrice.Left( 1 ).ToText = "$" ) Then
    Var intLen As Integer = strSellPrice.Length
    curSellPrice = strSellPrice.Right( intLen - 1 ).ToDouble
  Else
    curSellPrice = strSellPrice.ToDouble
  End If
  
  frmActiveTill.mthTillCalculator
  // Once the edit is made the record has to be updated...
  If( strDiscount <> "0.0" ) Then
    modTillActions.mthUpdSaleDetail( intLineCnt, strItemNomen, strCustId, strSaleId, intItemQty, strLineItemCode, strSaleState, "Yes", strDiscount, curSellPrice )
  Else
    modTillActions.mthUpdSaleDetail( intLineCnt, strItemNomen, strCustId, strSaleId, intItemQty, strLineItemCode, strSaleState, "No", strDiscount, curSellPrice )
  End If
  
Case 2
  // A future idea... that may never happen...
End Select

lstBxOrders.MouseDown

' Primary Variable Declaration(s)
Var rRow, cColumn As Integer
Var A As Integer

' Function(s) / Logic...
rRow = Me.RowFromXY(x, y)
cColumn = Me.ColumnFromXY(x, y)

If( cColumn ) = 3 Then // Quantity...
  Me.EditCellAt( rRow, cColumn )
  lstBxOrders.CellValueAt( rRow, 3 ) = A.ToText
  lstBxOrders.Refresh
  
ElseIf( cColumn ) = 4 Then // Price...
  Me.EditCellAt( rRow, cColumn )
  lstBxOrders.CellValueAt( rRow, 4 ) = "$" + A.ToText
  lstBxOrders.Refresh
  
ElseIf( cColumn ) = 5 Then // Discount...
  Me.EditCellAt( rRow, cColumn )
  lstBxOrders.CellValueAt( rRow, 5 ) = A.ToText
  lstBxOrders.Refresh
  // Update discount status in tblSalesDetail...
  
End If

It’s midnight here, so sorry if I am walking beside my shoes.

I see nothing to go out of the Cell in your CelKeyDown Event Code.

You set intRun to 1 if the depressed key was Enter or Return, then check intRun value and stays where you are.

I will read your code back (if needed) tomorrow at wake up time.

Well in my Derp D Derp moment…

I figured out how to format the cell the way I wanted and it’s working as expected…

strSellPrice = modSysFunc.mthFormatCurrency( strSellPrice )
Me.CellValueAt( Me.SelectedRowIndex, 4 ) = strSellPrice

The modSysFunc.mthFormatCurrency is a module I created to force a uniform format across all elements that need it. It works better than the TextBox.Format option in that it’s more reliable. I have had some wonky things happen… that were not planned and that I haven’t been able to sort out. Anyhow the Module.Method I wrote sets the format based on the input value… All I had to do was reassign it to the doggone cell! DERP!