Is it possible to change the Multiselect behaviour with a standard TListBox?
I would like items to only be multiselected by holding the Ctrl key, not the Shift key.
I have TActions which update depending on items selected, eg:
TAction(Sender).Enabled := ListBox1.ItemIndex <> -1;
The controls assigned to the action flicker when a listbox item is selected when holding shift to multiselect, this does not happen by holding ctrl key only.
So I would like to use only Ctrl key to multiselect.
Simply put, how can I:
- Multiselect TListBox
- Use Ctrl to multiselect
- Shift has no effect
Thanks 🙂
Item selection is processed by the default window procedure of the underlying list box api control. Because of this there’s no VCL property that would do this. Nevertheless, users might not like this, but you can change the behavior by handling
WM_LBUTTONDOWNmessage that is post the the control which triggers item selection. Subclass the control in any way you like. Or, since WM_LBUTTONDOWN is posted, you can useOnMessageevent of anApplicationEventscomponent. Or, just as one example below, if the control is immediately parented by the form, you can use the notification sent to the parent: