Mega Code Archive

 
Categories / Delphi / System
 

Force TListViews Edit Mode using a Keyboard Shortcut (F2 as in Windows Explorer)

Title: Force TListView's Edit Mode using a Keyboard Shortcut (F2 as in Windows Explorer) Delphi's TListView control displays a list of items in columns with column headers and sub-items, or vertically or horizontally, with small or large icons. The ReadOnly property of the list view determines whether the user can change the caption of a selected list view item. At run time, when ReadOnly is FALSE, the user can click the selected item to "enter" the edit mode. Upon entering the edit mode, the in-place editor for the item’s caption is placed "above" the selected item. The OnEditing and OnEdited events occur when the user begins and finishes editing the list item, respectively. You can try this using Window Explorer - as it lists the files in the folder in a list view type control. ListItem's Begin_Edit Keyboard Shortcut: F2 (for example) If you want to allow the user to start editing the caption of an item by a keyboard "shortcut", rather than by the mouse action (as described above), you need to handle the OnKeyDown event as: Note: ListView1 on Form1, handling the OnKeyDown. procedure TForm1.ListView1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState) ; begin //start editing on F2 key press if Key = VK_F2 then if Assigned(ListView1.Selected) then ListView1.Selected.EditCaption; end; The EditCaption method of a list item begins in-place editing of the list item's caption.