![]() |
The New VCL ControlList Multiple Selection in Delphi 11.3
What is a ControlList?
The*ControlList component was ![]() 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: http://blog.marcocantu.com/images/fo...trllist_01.png 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: http://blog.marcocantu.com/images/fo...trllist_02.png 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: http://blog.marcocantu.com/images/fo...trllist_03.png 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. ![]() |
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:48 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz