Delphi/Lazarus: Select all with CTRL+A in ListView
Tip by Delphian | 2013-10-05 at 12:37
If you have written an application in Delphi or Lazarus containing a TListView with some entries, it is quite nice to have the possibility to select all items of the ListView by pressing the key shortcut CTRL and A on the keyboard. Unfortunately, the ListView does not support this automatically.
But we can quickly remedy this by writing the following code in the OnKeyDown event of our ListView:
procedure Tprog.ListView1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var i: integer; begin if (Shift = [ssCtrl]) and (key = ord('A')) then begin ListView1.Items.BeginUpdate; for i := 0 to ListView1.Items.Count-1 do Items[i].Selected:=true; ListView1.Items.EndUpdate; end; end;
First of all, this code checks which keys have been pressed. If the keys are "CTRL" (Shift = [ssCTrl]) and "A", we go through all entries of the ListView and set "Selected" to "true". Of course, you can still add conditions for other keys or key combinations.
Important: To be able to select multiple items in the ListView at all, we have to set the property "MultiSelect" of our ListView to "true" before.
About the Author
The author has not added a profile short description yet.
Show Profile
Related Topics
Delphi/Lazarus: Delete selected items with DEL-key from ListView
Tip | 0 Comments
Delphi/Lazarus: Add Item or Line to ListView
Info | 0 Comments
Delphi/Lazarus: Why should I use BeginUpdate and EndUpdate?
Question | 1 Answer
Delphi/Lazarus: Delete selected Items from ListBox using DEL-Key
Tip | 3 Comments
Lazarus: Match FormDropFiles with a specific ListView
Tutorial | 0 Comments
Lazarus: CMD-Key in OnKeyDown Event on Mac OS X
Question | 1 Answer
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.