Pablo,

Here is some code you can try...

It is the Unit and DFM files for a very simple test I was doing...

It should come up and work as it is, but if not, then add in some more 
data..

Cheers,

Frank
> I have tried many examples, so I must doing something wrong .
> I am working on the virtuallistview example of turbo explorer (the same 
> of delphi 7) an I need to click on the column header and
> sort the list for that column like the Window$ explorer.
>
> Thanks
>
>
> Rob Kennedy escribió:
>
>   
>> pablo gietz wrote:
>>   
>>     
>>> I can't sort the column in a listview. I have tried the examples and 
>>> doesn't work.
>>>     
>>>       
>> What examples have you tried? In what ways did they not work? What were 
>> you expecting to happen, and what happened instead?
>>
>> http://www.catb.org/~esr/faqs/smart-questions.html#bespecific
>> http://www.catb.org/~esr/faqs/smart-questions.html#beprecise
>>
>>     

******************************
unit LV_u;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls;

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

var
  Form1: TForm1;
  o    : boolean;

implementation

{$R *.DFM}

function MySortProc(Item1, Item2 : TListItem; ParamSort: Integer): 
integer; stdcall;
var  t1, t2 : string;
begin
     case ParamSort of
        0 : begin
               t1 := Item1.Caption;
               t2 := Item2.Caption;
            end;
        1..4 : begin
               t1 := Item1.SubItems[ParamSort-1];
               t2 := Item2.SubItems[ParamSort-1];
            end;
     end;
     if o then
        result := lstrcmp(PChar(t1), PChar(t2))
     else
        result := -lstrcmp(PChar(t1), PChar(t2));
end;

procedure TForm1.ListView1ColumnClick(Sender: TObject;
  Column: TListColumn);
begin
     ListView1.CustomSort(@MySortProc, Column.Index);
     o := not o;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
     o := true;
end;

end.

*****************************************

object Form1: TForm1
  Left = 192
  Top = 107
  Caption = 'List View Sorting Test'
  ClientHeight = 266
  ClientWidth = 427
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnActivate = FormActivate
  PixelsPerInch = 96
  TextHeight = 13
  object ListView1: TListView
    Left = 16
    Top = 48
    Width = 409
    Height = 150
    Columns = <
      item
        Caption = 'No'
        Width = 30
      end
      item
        Caption = 'Name'
        Width = 90
      end
      item
        Caption = 'Addr1'
        Width = 90
      end
      item
        Caption = 'Addr2'
        Width = 90
      end
      item
        Caption = 'Town'
        Width = 90
      end>
    Items.ItemData = {
      01680100000500000000000000FFFFFFFFFFFFFFFF0400000000000000013100
      04460072006500640008730068006F0072007400200073007400000550006500
      72007400680000000000FFFFFFFFFFFFFFFF0400000000000000013200035400
      6F006D00000007420075006E00620075007200790000000000FFFFFFFFFFFFFF
      FF04000000000000000133000548006100720072007900093300340020004800
      6100790020005300740000055000650072007400680000000000FFFFFFFFFFFF
      FFFF04000000000000000134000341006C0066000D3200320020005300680065
      006E0074006F006E0020005200640000075300750062006900610063006F0000
      000000FFFFFFFFFFFFFFFF040000000000000001350005420065007400740079
      000A3900390020004400610076006500200052006400000641006C0062006100
      6E007900FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
      FFFFFFFFFFFFFFFFFFFFFFFF}
    TabOrder = 0
    ViewStyle = vsReport
    OnColumnClick = ListView1ColumnClick
  end
end
__________________________________________________
Delphi-Talk mailing list -> Delphi-Talk@elists.org
http://www.elists.org/mailman/listinfo/delphi-talk

Reply via email to