Mega Code Archive

 
Categories / Delphi / VCL
 

How to realize a MultiSelect in ShellListView

Title: How to realize a MultiSelect in ShellListView function SelectedFiles(AShellView: TShellListView): TStringList; begin Result := TStringList.Create; for i := 0 to shelllistview1.Items.Count - 1 do // is the item selected? if shelllistview1.Items[i].Selected = True then // Folders can also refer to files, which is why we check isFolder // before adding the filepath to the result if shelllistview1.folders[i].IsFolder = False then // add filepath and filename to result Result.Add(shelllistview1.Folders[i].PathName); end; Example usage: procedure TForm1.Button1Click(Sender: TObject); var i: Integer; FileList: TStringList; begin try FileList := TStringList.Create; //create stringlist to contain filenames FileList := SelectedFiles(ShellListView1); //populate tstringlist if FileList.Count = 0 then Exit; //exit if no files selected for i := 0 to FileList.Count - 1 do ShowMessage(FileList[i]); //cycle through each filename and do something finally FreeAndNil(FileList); //free tstringlist when finished end; end;