Einzelnen Beitrag anzeigen

Flom

Registriert seit: 19. Sep 2006
126 Beiträge
 
#7

Re: ListView 2 mal Sortieren nicht möglich?

  Alt 10. Feb 2007, 17:47
Delphi-Quellcode:
procedure TForm1.ListViewsColumnClick(Sender: TObject; Column: TListColumn);
begin
  ColumnToSort := Column.Index;
  (Sender as TCustomListView).AlphaSort;
end;

procedure TForm1.ListViewsCompare(Sender: TObject; Item1, Item2: TListItem; Data: Integer; var Compare: Integer);
var
  i:integer;
begin
  if ColumnToSort = 0 then
  Compare := CompareText(Item1.Caption, Item2.Caption)
  else
  begin
    i := ColumnToSort -1;
    Compare := CompareText(Item1.SubItems[i], Item2.SubItems[i]);
  end;
  if compare=0 then //wenn Einträge gleich sind, dann nach einer 2. Spalte sortieren
    begin
      if ColumnToSort2 = 0 then
      Compare := CompareText(Item1.Caption, Item2.Caption)
      else
      begin
        i := ColumnToSort2 -1;
        Compare := CompareText(Item1.SubItems[i], Item2.SubItems[i]);
      end;
    end;
end;
...

Delphi-Quellcode:
procedure TForm1.CreateFileList(Dir, Ext: String; UseSubDirs: Boolean);
var
SR: TSearchRec;
Item: TListItem;

begin
If FindFirst(Dir + '*.*', faAnyFile, SR) = 0 then
Repeat
  If (SR.Attr and faDirectory = faDirectory) and (SR.Name <> '.') and (SR.Name <> '..') and (UseSubDirs) then CreateFileList(IncludeTrailingPathDelimiter(Dir + SR.Name), Ext, UseSubDirs)
  Else If LowerCase(ExtractFileExt(SR.Name)) = LowerCase(Ext) then
   begin
    Application.ProcessMessages;
    ///////////////////////////////////////////////
    ///////////////////////////////////////////////
    Item := ListView4.Items.Add;
    Lese_ID3Tag(Dir + SR.Name);
    Item.Caption := ID3Tag.Artist;
    Item.SubItems.Add(ID3Tag.Titel);
    Item.SubItems.Add(SR.Name);
    Item.SubItems.Add(Dir);
   end;
   Label2.Caption:='Aktion: Suche Dateien';
Until FindNext(SR) <> 0;
FindClose(SR);
Label2.Caption:='Aktion: Fertig';
end;
der Aufruf:
Delphi-Quellcode:
procedure TForm1.SucheClick(Sender: TObject);
begin
ListView4.Clear;
if CheckBox_MP3.Checked = True then
CreateFileList(quelle + '\', '.mp3', CheckBox1.Checked);
if CheckBox_WMA.Checked = True then
CreateFileList(quelle + '\', '.wma', CheckBox1.Checked);
Label1.Caption:='Insgesamt: '+IntToStr(ListView4.Items.Count);
//////////////////////////////////////////////////////////////
ColumnToSort := 0; //hier also der Index der Spalte, nach der Sortiert werden soll
ListView4.AlphaSort;
end;
  Mit Zitat antworten Zitat