CTRL+A with no Main Menu Bar

I was working on a simple window with a listbox. I wanted to support CTRL+A to select all the entries the in listbox so I added the following code to KeyDown

[code] if Asc(Key) = 1 then ’ ctrl+a

For row As Integer = 0 to Listbox1.ListCount - 1
  Listbox1.Selected(row) = True

end if[/code]

I was a bit shocked when all it was doing was selecting the first entry in the list so I double checked that I have MultiSelect enabled. Odd I thought, it’s pretty straight forward, I seem to be getting stumped on the simplest of things since moving to Xojo. So I created a new project, added a listbox and a few dummy entries and my added my code above to the KeyDown event.

I was a bit surprised to see it working as expected, selecting all the entries in the listbox.

So I commented my code and was a bit surprised to see it working without any code. Maybe its the Main Menu Bar that’s added to the window as default on a new project. So I disabled the menu form the window and it went back to selecting the first entry in the list.

banging head on desk Having wasted an hour trying to figure out the problem, it would seem that things are happening without me coding them, why would CTRL+A now select the first entry in the list?

I added my code to KeyDown, removed the default menu item from the window and it seems to be overriding or ignoring my code and is still selecting the first entry in the list.

Argh. Does anyone know whats going on here?

I’ve not asked in to implement CTRL+A, or do anything with it, yet its doing something. Is there any way I can disable that so my code takes preference? I dont really want a MenuBar on the window if I need to have that there to implement the CTRL+A. Your thoughts are appreciated.

TIA (Thanks in advance) :slight_smile:

There are many key combinations that Windows handles on your behalf and routes through the menu system. The best approach is to use a menu.

I just created a default app in C# using Visual Studio and it didn’t add this functionality, I doubt its a windows thing, probably Xojo as I’ve never come across it before.

Note that you can implement menu handlers at the control level. It may be that Xojo has done this for you, but you can override it with your own. Also note that Xojo’s listbox is not a native control, so that certainly plays into it as well. In any case, there are many key combinations that will never make it to a KeyDown event, but are routed through the menu system, whether by Windows or by Xojo. It’s an idiosyncrasy of Xojo being an X-plat tool.

Thanks, I’ll have a read up on Menu Handlers. I’m only a few days into Xojo, so please excuse my frustration at getting snagged up on the simplest of tasks.

Is there a reason you don’t want a menu bar?

Its a waste of screen real estate on my simple app to have a menu that says File Exit (when there’s a cross on the window) and Edit Copy Select All when I have a context sensitive menu on the listbox. I generate the context sensitive menu on the listbox in code which has Copy and Select All on. I just want to be able to add text from the listbox to the clipboard so it can be used elsewhere.

Lots of windows don’t have menu bars, it just seems a little odd that I need one to implement CTRL + A.

I also note that shift+end isnt working, even though shift+down arrow does, this boggles my mind. I guess its good to know thats its not a standard windows control, but one would have thought that default features would have been first out of the box.

Welcome to Xojo. :slight_smile:

Just in case someone else comes across this thread, I’ve created a bug report here:

<https://xojo.com/issue/43706> Cannot use CTRL+A without menu being on window

and made a few more regarding:

<https://xojo.com/issue/43705> ListBox Shift+Down Arrow, Shift+Up Arrow incorrect behaviour
<https://xojo.com/issue/43704> ListBox Shift+End, Shift+Home incorrect behaviour