When a ListBox changed

I’d like to know if a ListBox has changed in order to give a message to save it.
I see that there is an event called “CellTextChange”, but it is only called when using keys, not when using “CellValueAt”.
Am I missing something?
Thanks in advance for any help.

maybe subclass this listbox and add your own computed property “changed” where you can set a flag or memory a status of an enumeration if the cell is changed. and a method ChangeCellValueAt(x)=


But a simple click in a Row fire it.

Search in this Forum for a complete example (if my memory is correct, one was chared some months ago).

Thank you Markus. I imagine that what you say it’s the way to do it, although I hoped it was a simpler way to do it. Maybe I will create a Feature Request.

Events are really for things that you don’t know are happening due to user/system interaction. If you’re calling a method on the ListBox to carry out an operation, then you know it’s happening and can add a method call directly after. You can add that method call to all instances where you update the ListBox to perform the necessary operations.

Thanks Emile. I had paid attention to ListBox.Change, but this event only reacts to clicking with the mouse, but not (at least accordingly to LR) with CellValuAt that changes the content of the ListBox.

Thanks Anthony. You’re right. But if you deal with old code and want to know if a ListBox has been changed, you have to study all the methods related with this ListBox to see if they change it.
I thought it would be great to use an event that took care of it by itself.

Unfortunately, that can create more issues than it solves where users code themselves in to StackOverflowExceptions and the like. It’s bad practice to notify of an operation that the developer already knows they initiated, typically, in a synchronous environment.

Using the LR you can see what methods you can call to alter cell content and search for them in the IDE, or refactor your current approach.

May be you’re right. I’ll try to find all the points where the listbox is changed and set a flag to know, at the “close” event, if is has been changed or not.

Populate it, and copy the cell contents into the rowtags
When the window closes, compare the rowtags with the cell contents.
If any are different, save it.

1 Like

Thank you Jeff. It is a nice solution for me, although it wouldn’t accommodate the case when someone uses the tags. Fortunately it’s not my case.

But this is your app.
Are you creating some subclass you want to sell on as a custom control, where ‘someone else’ might do something unexpected?
If so, add a dictionary of your own, and populate that instead of rowtags

or even use an array

1 Like

I prefer having an object in the rowtag, keeping all the row data in the correct datatypes. Calculations, saving etc. gets so much easier.

1 Like

is it possible to subclass the listbox and add a new property which is similar to rowtag??

Of course it is. In My MegableCelListbox Subcass that I wrote 0ver 10 years ago I did it. I needed to use the RowTags but needed to keep them available for end users…The Way I subclassed it to the end user It has the normal listbox RowTag API so lookalike the bult-in Listbox cell tag

there is also a CellTagAt(row as Integer, column as Integer)
you could compare before and after.

i swear the other controls raise a change event if the text was assigned in code and not by user.
same if a listindex is changed by code for popup or combobox.

Some certainly do! Off the top of my head:

TextField.TextChange is raised if you change the value by code.
Checkbox.Action is raised if you change the value by code.

It’s down to the details I think, because Listbox.Change will be raised if you RemoveAllRows or remove a row that is selected.

I agree with @Anthony_G_Cyphers that if you’re changing the cell value in code you have every ability to call a function to save the Listbox contents.

Update: RemoveAllRows only causes Change if something was selected.


As @Tim_Parnell said, some do. And the number of times I’ve seen people shoot themselves in the foot as a result is quite large.

1 Like