ALL >> Computer-Programming >> View Article
The New Vcl Controllist Multiple Selection In Delphi 11.3
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:
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:
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:
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
Add Comment
Computer Programming Articles
1. Which Institute Is Best For Coding And Programming In Bhopal?Author: Shankar Singh
2. Top 9 Benefits Of Custom Mobile Application Development
Author: Byteahead
3. Top 10 Creative Business Ideas For Entrepreneurs
Author: Byteahead
4. Top 10 Apps Like Tiktok Everyone Should Check Out
Author: Byteahead
5. Is The Apple Watch Series 7 Worth It For Seniors?
Author: Ashish
6. The Ultimate Guide To Ebay Product Listing Services: Elevate Your Online Store
Author: rachelvandereg
7. Which Are The Best Java Coding Classes In Bhopal?
Author: Shankar Singh
8. Warehouse Management In Zambia: Essential Features To Look For
Author: Doris Rose
9. Ecommerce Web Design And Development In Melbourne With The Merchant Buddy
Author: themerchantbuddy
10. Why Website Maintenance Is Crucial For Business Success
Author: Yogendra Shinde
11. Boost Your Business With Smart Invoice Pos Software In Zambia
Author: Cecilia Robert
12. How Stablecoin Development Ensures Stability And Security?
Author: Michael noah
13. Công Cụ Tính Chiều Cao Chuẩn Từ Minbin Tool: Đo Lường Và Cải Thiện Chiều Cao Hiệu Quả
Author: KenJi123
14. How To Make A Courier App For Courier Delivery And Tracking Service
Author: Deorwine Infotech
15. Reputation Management In The Digital Age: Protecting And Enhancing Your Law Firm’s Image
Author: jamewilliams