The TShellListView control (a part of the Shell Controls package) can be used to display files from the file system. Paired with TShellTreeView shell, the TShellListView can be used to mimic Windows Explorer user interface.
The full name (path) of the selected file is stored in the PathName property of the SelectedFolder property. That is, if a file is selected in a shell list view, to get its name you can read: ShellListView1.SelectedFolder.PathName.
Note that SelectedFolder is of the TShellFolder type, and its IsFolder property will actually tell you if the selected item is a folder or a file.
MultiSelect in TShellListViewWhen MultiSelect property is set (to true) for the shell list view, to get the list of selected files, you need to iterate through items and check if an item is selected.
Here's an example of drag-dropping selected files from the TShellListView to a TMemo control. Drop a TMemo control on a form, name it "memoSelectedFiles". Drop a TShellListView.
Handle Memo's OnDragDrop and OnDragOver events as:
//handles Memo's OnDragDropTest: select a few files in the shell list view and drag them over the memo, than drop. In the memo, you'll see a list of file names being selected / dropped.
procedure TSimpleFilesForm.memoSelectedFilesDragDrop(Sender, Source: TObject; X, Y: Integer);
slv : TShellListView;
slv := TShellListView(Source);
files := TStringList.Create;
if NOT slv.MultiSelect then
for cnt := 0 to -1 + slv.Items.Count do
//selected and NOT folder
if slv.Items[cnt].Selected AND (NOT slv.Folders[cnt].IsFolder) then
//display selected files in memo
//handles Memo's OnDragOver
procedure TSimpleFilesForm.memoSelectedFilesDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
Accept := Source is TShellListView;
Read Understanding Drag and Drop Operations for a better understanding of OnDragDrop and OnDragOver events and their handling.
Delphi tips navigator:
» Deactivating TShellTreeView
« Selecting Delphi's TListView Item on Item Check / UnCheck