In a Desktop app I'm working on (for both macOS & Windows), I have a Listbox that I've built as a Hierarchical TreeView.
Naturally, because most TreeViews in applications or operating system file managers allow navigating a TreeView using your keyboard arrow keys, I coded some handling for the folders in the tree structure, where the Left arrow key will "collapse" the currently highlighted folder and the Right arrow key will "expand" the folder. Of course the Up & Down arrows move up and down the items in the tree.
I have the folders collapsing and expanding properly in my code, but my problem is that when you use the left or right arrow keys in a Listbox on macOS, it makes an alert sound (bonk). The sound does not occur when going up or down in the Listbox, because I think this sort of navigation is a standard feature of the Listbox. But going left or right is not?
The following is my KeyDown event of my Hierarchical Listbox.
Select Case AscB(Key) Case 28 Self.LastArrowKey = ArrowKey.Left If Me.ListIndex >= 0 And Me.RowTag(Me.ListIndex) = ItemType.Folder And Me.Expanded(Me.ListIndex) Then Me.Expanded(Me.ListIndex) = False End If Case 29 Self.LastArrowKey = ArrowKey.Right If Me.ListIndex >= 0 And Me.RowTag(Me.ListIndex) = ItemType.Folder And Not Me.Expanded(Me.ListIndex) Then Me.Expanded(Me.ListIndex) = True End If Case 30 Self.LastArrowKey = ArrowKey.Up Case 31 Self.LastArrowKey = ArrowKey.Down Else Self.LastArrowKey = ArrowKey.None End Select Return False
Note: This sound appears to happen on macOS whether the Listbox is hierarchical or not. And when testing my app in Windows 10, there is no sound made when using the left or right arrow keys.
If anyone has a tip or suggestion on how to prevent this sound, I would appreciate it. Thanks.
Xojo Version 2019r1.1
Mac version: Mojave 10.14.5