123ArticleOnline Logo
Welcome to 123ArticleOnline.com!
ALL >> Computer-Programming >> View Article

The New Vcl Controllist Multiple Selection In Delphi 11.3

Profile Picture
By Author: Embarcadero Technologies
Total Articles: 3
Comment this article
Facebook ShareTwitter ShareGoogle+ ShareTwitter Share

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:

multiple selection

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


procedure TForm19.ControlList1BeforeDrawItem(AIndex: ...
... Integer; ACanvas: TCanvas;

ARect: TRect; AState: TOwnerDrawState);

begin

Label1.Caption := 'Item ' + (AIndex + 1).ToString;

end;

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:

multiple selection

Now you can check the selected item by using:


Memo1.Lines.Text := 'Single selection: ' + (ControlList1.ItemIndex + 1).ToString;

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:

multiple selection

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


for var I := 0 to ControlList1.ItemCount - 1 do

if ControlList1.Selected[I] then

Memo1.Lines.Add((I + 1).ToString);

That's all you need to do to use this new feature of the powerful ControlList VCL component. Visit https://www.embarcadero.com/products/delphi to find more about new features and improvements in Delphi 11.3

Total Views: 75Word Count: 430See All articles From Author

Add Comment

Computer Programming Articles

1. Unlock Your Potential With Xamarin Developer Certification
Author: EDCHART

2. Unlock Your Potential With Edchart's Flutter Developer Certification Exam - Free Test
Author: EDCHART

3. Navigating Success: Hiring Dedicated Php Developers For Your Next Project
Author: Quickway Infosystems

4. Cmmc Gap Analysis: Roadmap To Compliance
Author: Karmai

5. Hire Skilled Android App Developers
Author: John

6. How To Scrape Liquor Prices And Delivery Status From Total Wine And Store?
Author: Productdatascrape

7. Kotlin Certification |kotlin Developer Certification -by Edchart
Author: EDCHART

8. Empowering Careers: A Comprehensive Review Of Scope India Software Training Institute
Author: scope india

9. Double-sided And Multilayer Pcb Manufacturer: Rapid Circuit Leading The Way
Author: RICKY

10. 8 Reasons To Automate Your Cmmc 2+ Compliance With Karmai Consulting
Author: Karmai

11. Tips For Preparing Your Home For Nbn Installation
Author: hartnettcrews

12. How To Maximize Revenue By Web Scraping Tripadvisor Hotels Data?
Author: #WebScrapingTripAdvisorHotelsData

13. Secure And Comply: Essential Hipaa Compliance Checklist
Author: MakeForms

14. Enhancing Your App’s User Interface With React Native Ui Libraries
Author: matthew brain

15. Navigating The Divide: Data Security Management Vs Cloud Security Management
Author: Karmai

Login To Account
Login Email:
Password:
Forgot Password?
New User?
Sign Up Newsletter
Email Address: