was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

29 Visitors Online


 
... ein MultiSelect in einem ShellListView realisieren?
Autor: Owen Barnes
[ Tip ausdrucken ]  

Tip Bewertung (15):  
     


{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ShellListView does not have a files property (common in dialogs eg TOpendialog),
therefore we have to cycle through each item to find out whether the
item is selected or not.

Use this function to obtain a list of selected files in a 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;

// ---------- 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;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners