Enter vs Tab in ListBox

Ok, this is weird.

If I use an ActiveCell.Mask or ActiveCell.Format on a cell, it works fine if I tab out of the cell, but doesn’t work if I hit Return/Enter. Why is that?

A bug ? A default in the implementation ? “A Feature” ?

So this is a known issue?

You can apply the mask yourself through Cell() in CellLostFocus.

Ok, I’m confused. What’s the proper way to use ActiveCell.Mask and ActiveCell.Format? (I’ve read the docs) and they don’t really explain it with a full example that I can find.

If I have a cell set as an Editable cell, what event is triggered when I go to edit a cell (normally it goes into edit mode on double-click on it’s own) and where should the ActiveCell properties be set? I was using CellClick, but then have to manually put the cell into Edit Mode using EditCell(), and I’d prefer the cell edits when double-clicked as per normal.

Sorry, not double-clicked, but clicked a 2nd time after selecting a row.

If I use CellGotFocus, I still don’t get the format applied when pressing Enter.

Return/Enter usually has a very different meaning than Tab. What are you trying to achieve?

It does? How so?
Every software I’ve ever seen, enter/return means you’re done editing, as does Tab, except that you’d like to move on to the next control. Esc means you want to cancel your changes.

What do you think Enter/Return means?

Tab means “go to the next field”. It fires the code associated with “blurring” the current control (LostFocus in Xojo parlance). Enter means “fire the default button”. It’s up to the programmer to deal with whatever control has focus at that moment. “Blur” doesn’t happen. We programmers jump a lot of hoops to make it look like they do the same thing.

Interesting. All modern UI that I’ve seen, Enter/Return fires the button that HAS THE FOCUS. Since no button should have focus when you’re editing a text field, (the text field does), Enter should complete the edit. This is what users expect of any modern UI.
Very odd that Xojo doesn’t follow these standards. Completely unexpected, and I’ve been programming for dozens of years!

Ok, well, I’ll just have to add some code then that somehow tells the control to end editing when Enter/Return is pressed.
I assume it won’t respond to escape properly either?

Looks like Escape works at least! :slight_smile:

I have seen some environments that treat Tab and Enter the same, but in my experience, they are the exception. But then, I’ve been programming mainly in Windows OS and Web technologies. I believe the current UI “standard” conforms to the web, where Tab and Enter are completely different.

Interesting. I have never heard of this before. All my programming until a couple of years ago was on Windows. Enter always completes the edit on UIs I’ve seen, even on the web.
I would be interested to see where it doesn’t, and why Xojo chose this way of working. It’s definitely not the Windows (or OSX) way of working.

So, in Xojo, Enter works to finish the edit, but the ActiveCell.Format is not applied. It’s only applied when Tab is pressed. So this problem I think has more to do with the ActiveCell.Format() property than whether an Enter or Tab completes an edit.

Why ActiveCell.Format() is being applied only on Tab is a mystery.
Both Tab and Enter fire the CellAction() event.
When and where does ActiveCell.Format() get applied?

Enter should trigger the default button, whereas Tab indeed goes to the next field and applies format.

What you can do, as I tried to tell you above, is to apply the format yourself in CellLostFocus.

For instance:

Me.Cell(Row, Column) = Format(Val(me.Cell(Row, Column)), "###,###.00")

Thank you Michel.
Weird thing is that Enter doesn’t trigger the default button, it just ends the edit WITHOUT applying the format. Acts like a bug.

Your solution doesn’t work as pressing Esc (which should always revert an edit) also fires CellLostFocus. A better place for your code would be the CellAction event, which gets fired by Tab AND Enter, but not Esc.

Because CellAction is fired every time, ActiveCell.Format() not being called HAS to be a bug.

Appreciate the help.

You can use CellKeyDown instead. That way you can test Key.

Thanks, but using CellAction seems to be the best way.

I still think this is a bug. How does one go about reporting bugs?

CellAction does not tell you which key was pressed. You need to know which key is pressed to format the cell if the user presses Enter.

Apparently, CellAction does not fire when user presses ESC as well.

Go to xojo.com, click Extras, and download the Feedback app. It is the bug reporting tool.