Close window save listbox change

I have a listbox with several rows of content which is in a Modal window.
I have a button that makes a cell of the selected row editable. So I click on that button.

If I change the content of that cell and hit the TAB key, the CellAction event occurs. In the CellAction event code, I can grab the new content of the cell.

Dim newValue As String newValue = Me.Cell(row, column)

Then I can do various things in the code of the CellAction event (in my case update a database value).

However, if I change the content of that cell and click on the Close Window button of the Modal Window, I have problems. The CellAction event still occurs but

Dim newValue As String newValue = Me.Cell(row, column)

does not populate newValue with the value that was just typed. Rather it (variable newValue) gets the value that was present before any editing occurred.

I am confused by this.

Is there a way to get the Me.Cell(row, column) to contain the most recently typed value when the CellAction code is doing its thing?

In my testing (on Windows), this seems to work as expected. What OS are you experiencing this on?

Mac. Xojo 2017 R3

Running the application in the IDE or in the StandAlone ?

Try ActiveCell instead of Cell(). If it’s still editable, the data won’t have transferred back to the cell yet.

http://documentation.xojo.com/index.php/ListBox.ActiveCell

Per your (Greg) suggestion, I tried ActiveCell.

Dim newValue As String // newValue = Me.Cell(row, column) newValue = Me.ActiveCell.Text

The result is the same. Hitting the Close button on the window does fire off the CellAction event, but as the code is running through that event, Me.Cell(row, column) and Me.ActiveCell.Text both have not changed to the text the user has just typed into the cell.

As per Emile Schwarz, compiling a Mac version and running that does not change this behavior.

[code]Const NO_ROW_SELECTED = -1

If lbHelp.ListIndex <> NO_ROW_SELECTED Then // One of the rows is selected
lbHelp.EditCell(0, 0)
End If[/code]

I have used this somewhat kludgy way to solve the problem. This code is put in the Window.Close event. By declaring another cell in the listbox an editable cell, this apparently forces the entry the user has made to his/her cell to “register”. The CellAction event occurs after this code is run and now the cell that was being edited gets its value set to what the user typed.

I don’ really like this solution because it relies on the order in which the code in Window.Close and CellAction are run and I am not sure this is documented. But, for now, it makes my code work.

Sounds like the focus change is what’s causing the cell to register the changes. Try using just self.setfocus in the window’s Close or CancelClose events.

Tanner, I tried your suggestion because it seems “cleaner”. I am running in interpreted from the Mac IDE.
Putting Self.SetFocus in the Close event of the Window consistently (5 out of 5 trys) caused a crash (quit unexpected) when I would attempt to reopen the database after the window had closed.

Restarting the program, I could open the database, but the editing change had not been captured.

Putting the Self.SetFocus in the CancelClose event of the Window and returning False did not cause a crash when the database was reopened. The change the user made had been saved. So that is a successful strategy in my hands and is what I am adapting because I think it makes the code more “understandable”, although my original solution worked just fine.

Thanks for the follow-up. Glad you got it resolved :slight_smile: