ListViewde Başlığa Göre Sıralama (String,Integer,Date,Time)

Yazdığınız makaleleri ve üyelerimizin işine yarayacağını düşündüğünüz kodlarınızı gönderebilirsiniz. Bu foruma soru sormayın!
Cevapla
Kullanıcı avatarı
sadettinpolat
Moderator
Mesajlar: 2131
Kayıt: 07 Ara 2003 02:51
Konum: Ankara
İletişim:

ListViewde Başlığa Göre Sıralama (String,Integer,Date,Time)

Mesaj gönderen sadettinpolat »

Unit1.dfm

Kod: Tümünü seç

object Form1: TForm1
  Left = 260
  Top = 379
  BorderIcons = [biSystemMenu]
  BorderStyle = bsSingle
  Caption = 'Listview de sıralama nasıl yapılır?'
  ClientHeight = 198
  ClientWidth = 516
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  Position = poScreenCenter
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 8
    Top = 176
    Width = 214
    Height = 13
    Caption = 'Sıralama yapmak istediğiniz sütuna tıklayınız...'
  end
  object ListView1: TListView
    Left = 8
    Top = 16
    Width = 497
    Height = 150
    Columns = <
      item
        Caption = 'Dosya Adı'
        Width = 100
      end
      item
        Alignment = taRightJustify
        Caption = 'Boyut (KB)'
      end
      item
        Caption = 'Dizin'
        Width = 200
      end
      item
        Caption = 'Tarih'
        Width = 75
      end
      item
        Caption = 'Saat'
      end>
    Items.Data = {
      B80100000700000000000000FFFFFFFFFFFFFFFF04000000000000000C417574
      6F457865632E626174013503433A5C0A32322E30352E313938300531313A3232
      00000000FFFFFFFFFFFFFFFF04000000000000000A436F6E6669672E53797302
      313003433A5C0A31312E31312E323030320530303A3030FFFFFFFFFFFFFFFFFF
      FFFFFF040000000000000005412E426174013304433A5C410A30312E30312E32
      3030340530353A323200000000FFFFFFFFFFFFFFFF0400000000000000055A2E
      657865013104433A5C5A0A30312E30392E313939390530393A343500000000FF
      FFFFFFFFFFFFFF040000000000000005412E42617402313503443A5C0A30312E
      30312E323030340531313A303500000000FFFFFFFFFFFFFFFF04000000000000
      0005412E6D7033043335303006443A5C4D70330A30322E30322E323030340530
      323A323200000000FFFFFFFFFFFFFFFF040000000000000009596564656B2E5A
      69700335353508453A5C596564656B0A31322E31322E323030300531303A3131
      FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
      FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF}
    TabOrder = 0
    ViewStyle = vsReport
    OnColumnClick = ListView1ColumnClick
  end
end

Unit1.pas

Kod: Tümünü seç

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls,math,dateutils, StdCtrls;

type
  TForm1 = class(TForm)
    ListView1: TListView;
    Label1: TLabel;
    procedure ListView1ColumnClick(Sender: TObject; Column: TListColumn);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  fsort:integer;

implementation

{$R *.dfm}
function customsortproc(item1,item2:tlistitem;paramsprt:integer):integer;stdcall;
begin
case fsort of
0:   result := lstrcmp(pchar(tlistitem(item1).Caption),  pchar(tlistitem(item2).Caption));
1:   result :=  CompareValue(StrToInt(tlistitem(item1).SubItems[fsort-1]),  StrToInt(tlistitem(item2).SubItems[fsort-1]));
2:   result :=  lstrcmp(pchar(tlistitem(item1).SubItems[fsort-1]),  pchar(tlistitem(item2).SubItems[fsort-1]));
3:   result :=  CompareDate(StrToDate(tlistitem(item1).SubItems[fsort-1]),  StrToDate(tlistitem(item2).SubItems[fsort-1]));
4:   result :=  CompareTime(StrToTime(tlistitem(item1).SubItems[fsort-1]),  StrToTime(tlistitem(item2).SubItems[fsort-1]));
end
End;



procedure TForm1.ListView1ColumnClick(Sender: TObject;
  Column: TListColumn);
begin
fsort := column.Index;
ListView1.CustomSort(@customsortproc,0);
end;

end.
"Sevmek, ne zaman vazgececegini bilmektir." dedi, bana.

---
http://sadettinpolat.blogspot.com/
Cevapla