KeyDown running SelectionChanged code?

I have noticed an odd (what I can only assume to be) bug in 2023 Release 4.

I haven’t updated one of my apps in over a year, and when compiling it under 2023 R4 I have noticed that any code in the SelectionChanged event is firing when the Keydown event is triggered. Since I have the code in these two essentially mirroring each other, the result is happening twice now. To test, I added some code specifically to SelectionChanged and not in Keydown, and that new code fires as well when Keydown is triggered. I even migrated my code from AP1 to AP2, and the same issue is there. Has anyone else seen this?

Is this for Desktop projects?
Any control that offers KeyDown and SelectionChanged or a particular control (Text Field, Text Area, Combo Box, Popup Menu)?
Do you have a sample project that you can share?

Desktop Project with Desktop ComboBox.

I’m sorry, I can’t reproduce your problem with Xojo2023r4 running on a mac.
If you can share a sample project using dropbox, google drive or onedrive, someone can review and help.

Just ran it on my Mac. Problem is there too.

Sample project is here. ComboBox has three rows, Test1, Test2, Test3. Start typing “Test” and move down with arrow keys and select one of the rows with the Return key. A message box from SelectionChanged will fire off.

It’s not a good idea to use MessageBox for debugging, suggest you use

System.DebugLog CurrentMethodName


System.DebugLog CurrentMethodName + " " + str(asc(key))

in the Keydown Event instead.

In any case, I’m not seeing anything unusual here on macOS - when I select a row (using either the mouse or the Enter key) SelectionChanged fires. Isn’t that correct behavior for when a row is selected?

Here is what I see when I type the letters “T” and “E” then hit the down arrow key 3 times then the Enter key:

My Application Launched
Window1.ComboBox1.KeyDown 116 // T
Window1.ComboBox1.KeyDown 101 // E
Window1.ComboBox1.KeyDown 31 // Down arrow
Window1.ComboBox1.KeyDown 13 // Enter

Edit to add:

On second thought, perhaps it is a little weird:

  • If you hit DownArrow multiple times, you only get a single KeyDown event.
  • if you hit Enter with the menu open, you get Keydown 13 and the SelectionChanged event. Perhaps it should not send the Keydown 13?
  • if you hit Enter with the menu not open, you only get Keydown 13, but no SelectionChanged event at all.
1 Like

I like using Message box for simplicity and speed, and this not a rabbit hole we need to go down here.

No, that is not the correct behavior for when you choose Enter/Return. Clicking with the mouse fires off Selection Changed, hitting Enter/Return fires KeyDown. This is how I have used it in my application for many years and many different versions of Xojo.

Which version?

Here’s the same thing running in Xojo 2019R1.1 on macOS Ventura:

combobox Launched (Xojo 2019r1.1)
Window1.ComboBox1.KeyDown 84 // T
Window1.ComboBox1.KeyDown 101 // E
Window1.ComboBox1.KeyDown 31 // DownArrow
Window1.ComboBox1.KeyDown 13 // Enter

So in this older version of Xojo, you also get the Enter keydown event, but for some reason the Change event fires twice.

Multiple versions over the years. I upgraded this past summer for the first time in about 3 years, but hadn’t needed to recompile until now at version 2023R4. It’s only now that the problem has appeared.

I remember a bug report stating that that is not the correct behavior, as you actually are changing the Selection so SelectionChanged should fire too.

In other words, Xojo ‘fixed’ a bug that now when you select something using the keyboard (arrows/enter) the SelectionChanged event fires too.

I can’t find the bug report at this time.

1 Like

Interesting. So I no longer need to duplicate the code in a KeyDown event.

Just yanked out my KeyDown event and it’s working regardless of if the user chooses the row with the mouse or does it all by keyboard. Hadn’t realized a bug was preventing this in the past. Figured it had to be that way (using both). Thanks!!!

1 Like

I think there’s actually a bug here. Try this in your demo:

Type T, e, then hit Enter.

Result: the combobox will now contain “Test1” however the SelectionChanged event never fires. From the user’s perspective, hitting Enter should commit the data, so the lack of that event seems like incorrect behavior.

1 Like

I agree, if the options are not shown (no arrows used) when you hit Enter the SelectionChanged is not fired. I modified the sample to have “Aest1”, “Pest1”, “Test1” and typing A - Enter - P - Enter - T - Enter shows Aest1/Pest1/Test1 and SelectionChanged never fires.

Crap! You’re right. Jeez Xojo…get it right one way or the other!