whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

19 Visitors Online


 
...realize a MultiSelect in ShellListView?
Autor: Owen Barnes
[ Print tip ]  

Tip Rating (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;


 

Rate this tip:

poor
very good


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