Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
News

The New VCL ControlList Multiple Selection in Delphi 11.3

There is a small new features in the VCL library in the recently released Delphi 11.3, the option to enable multiple selection in the ControlList component of the VCL library.


What is a ControlList?

The ControlList component was introduced to the VCL a few years back to allow managing extremely large lists in a totally virtual way. A control list, in fact, has a panel with a structure that is created in a single instance in memory, but is painted for each of the list items, so that is looks like you have thousands, or even millions of such elements.

This is done by asking the program to update the controls of this panel each time of the items needs to be painted. Given that the paint requests are received only for the (few) visible items, the list does only the minimum processing required to give the perception of having a large amount of elements a user can scroll and navigate.

In practical terms, in a very minimal scenario (a list only one label) the component at design time will look like this:

ctrllist_01-7425732

The code responsible to making each item unique and distinct can be like the following:

Notice that the control list items don’t exist and don’t have the concept of status. Accessing¬†the Label1 Caption, outside of the specific ControlList event handlers use to process an element, makes no sense. After setting the list ItemCount¬†property to 100 items, this results will be the following UI:

ctrllist_02-8802161

Now you can check the selected item by using:

The ControlList Multiple Selection

What is new in Delphi 11.3 is the ability to enable multiple selection. This is done with the new MultiSelect property.

With this configuration, the user of your application¬†can click the mouse button along with the Ctrl and Shift keys to select multiple individual items (Ctrl) or all the items from the last click position (Shift), on the line of the classic behavior of a Windows ListBox with multiple selection. The same combinations can be use to unselect items, so that the Ctrl+click oepration is actually a “toggle selection” operations. Here is an example of this bare bone UI:

ctrllist_03-1320478

To check programmatically which items are selected, you can iterate over the Selected array property, with code similar to:

That’s all you need to do to use this¬†new feature of the powerful ControlList VCL component.


What's Next
Delphi Enter the Digital Fan Art and AI Art Contest
Delphi Fan Art Contest

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

About author

Marco is one of the RAD Studio Product Managers, focused on Delphi. He's the best selling author of over 20 books on Delphi.

2 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES