I have a question on menu item Edit Select All. Is this fully automated?
I’m on a Mac.
I have a listbox and want to give the user the option to select all items in it. If a single row is selected the row is then opened for edit through the change event; multiple selection (hold down the cmd or shift key) and the change event is immediately exited.
When I used the Select All menu item the change event is running for the first row in the list, the rest are being selected. The change event is running despite me putting code in the Select All menu handler to skip Change in these circumstances.
I put a breakpoint on the handler to make sure my exit immediately flag was being set and ran again. The program didn’t break suggesting the handler isn’t actually being called.
I deleted the menu handler from the window, but the menu item is still enabled and still behaved as outlined above.
Very strangely, if I use the shortcut (?-A) the change event isn’t called and all the rows are selected - even if the menu handler is deleted on the window.
Yes - I’m familiar the the Selected property … that’s the code I had in my menu handler … except it’s not being called.
I would be happy to show the code except there is none. The menu item is enabled whether there is a handler there or not, hence my question.
in your Listbox window, is the property Menus - MenuBar clear or not. If not, what is its name ? The name of your MenuBar ? If not, change that to MainMenuBar.
By default, a new window have that property blank.
If you want help, you HAVE to give food for understanding what you have / what ypu have done. Else, it is pure guesses.
May have a partial explanation.
I managed to get a breakpoint to work in another method called from the listbox’s change event.
After running the Select All the program hit the breakpoint and I was able to check the Focus property of the window. The
listbox was the control with focus. I added some code to force focus onto another control (a search box) and the menu handler worked. If the listbox has focus, Select All seems to be completely automatic, if another control has focus I seem to be able to properly implement Select All.
Previous question:
The ListBox have the focus, I activate Select All, nothing happens.
I do not set anything (nor the SelectAll MenuHandler) in that window (Window1).
I’m sorry … I really do get that.
Here’s my code in the Select All menu handler
initialising = True
for i as Integer = 0 to squadList.LastRowIndex
squadList.Selected(i) = True
next
initialising = False
Return True
Initialising is just a flag to jump out of the change event.
At the bottom of the window’s open event I have a
searchField.setfocus
Without that the listbox has focus and if I run Edit - Select All the menu handler is not called, the above code is not run but all rows in the listbox will be selected and the change event run.
With the setFocus, the handler is run.
I replaced my code with yours and removed the SetFocus in the window’s change event and ran. The change event ran so I put in my initialising statements to skip it and tried again. The change event still ran. I put a breakpoint in the menu handler and tried again. The program didn’t break and the change event ran suggesting the handler hadn’t been called.
Put the setFocus back in and program worked as intended.
I agree, I do not need to set focus for the code to work. If the only requirement was to select all the rows then fine, the solution works. But I have to prevent the change event from running and to do that I need the menu handler to run and if the listbox has focus the change event doesn’t seem to run, it appears to function automatically.
It would seem I need to force focus away from he listbox to get the Select All event to run.
You need to set the Focus to the ListBox only if you have other Controls in that window and you want to SelectAll for these.
In a project, I have a window with a bunch of TextFields, a Canvas, a ListBox and a TextArea. In that Case, I used the Focus to differenciate between the Controls.
In the link I provided above, you can read:
Gets or sets the RectControl in the window that has the focus. If no control has the focus, this property is Nil.
That means you can set Window1.Focus = Nil to clear the focus (no Control will have the Focus). (or Self.Focus = Nil to avoid the window Reference to Window1 ).
In the Change Event, excepted if the below code have to do something, you can check if there is more than one Selected Row and exits in that case.