Link to home
Start Free TrialLog in
Avatar of k4hvd77
k4hvd77Flag for Germany

asked on

Sorting TListView

Hello, I would sort a TListView by Clicking on the column (containes DateTime). Could You help me there?
Avatar of sftweng
sftweng

The first part is to determine which column the mouse is in. Try something like this:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    ListView1: TListView;
    StatusBar1: TStatusBar;
    procedure ListView1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ListView1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  StatusBar1.Panels[0].Text := IntToStr(x);
  StatusBar1.Panels[1].Text := IntToStr(y);
  IF (X > ListView1.Columns[0].Width)
  THEN StatusBar1.Panels[2].Text := 'Column 2'
  ELSE StatusBar1.Panels[2].Text := 'Column 1';
end;

end.
Of course a better way to get the column is to use an OnColumnClick event.

procedure TForm1.ListView1ColumnClick(Sender: TObject;
  Column: TListColumn);
begin

end;
Avatar of k4hvd77

ASKER

but How can I sort it?
Do you want to sort by Caption, Data or Both?
Avatar of k4hvd77

ASKER

I would sort by caption (Caption contains TDateTime)
ASKER CERTIFIED SOLUTION
Avatar of sftweng
sftweng

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of k4hvd77

ASKER

Exact that what I want :)