我看过好多软件(outlook\foxmail)里面都使用 STRINGGRID 控件,如何实现点击 fixedrow 时,可以进行排序?
    在windows里能否找到这种控件,或者提供一个下载?    我在此表示强烈谢意!

解决方案 »

  1.   

    首先,他们不一定用的是stringgrid,他们用的可能是listview,listview有排序功能,但要自己写如果用stringgrid,想排序的话,也要自己写函数
      

  2.   

    这个是我很早以前写的listview排序的一个演示  给你看看unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ComCtrls;type
      TForm1 = class(TForm)
        l: TListView;
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        Button4: TButton;
        Button5: TButton;
        Button6: TButton;
        Button7: TButton;
        procedure lColumnClick(Sender: TObject; Column: TListColumn);
        procedure Button4Click(Sender: TObject);
        procedure Button5Click(Sender: TObject);
        procedure Button6Click(Sender: TObject);
        procedure Button7Click(Sender: TObject);
        procedure lCompare(Sender: TObject; Item1, Item2: TListItem;
          Data: Integer; var Compare: Integer);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      num,oldnum,sorttype:integer;implementation{$R *.dfm}procedure TForm1.lColumnClick(Sender: TObject; Column: TListColumn);
    begin
       num:=column.Index;
       if oldnum=num then sorttype:=sorttype*(-1) else;
       l.CustomSort(nil,1);
       oldnum:=num;
    end;procedure TForm1.lCompare(Sender: TObject; Item1, Item2: TListItem;
      Data: Integer; var Compare: Integer);begincase sorttype of
     -1:if num=0 then if item1.Caption > item2.caption then compare:=1
          else if item1.Caption = item2.caption then compare:=0
          else compare :=-1
        else if item1.SubItems.Strings[num-1]>item2.SubItems.Strings[num-1] then compare:=1
        else if item1.SubItems.Strings[num-1]=item2.SubItems.Strings[num-1] then compare:=0
        else compare:=-1;
      1:if num=0 then if item1.Caption > item2.caption then compare:=-1
          else if item1.Caption = item2.caption then compare:=0
          else compare :=1
        else if item1.SubItems.Strings[num-1]>item2.SubItems.Strings[num-1] then compare:=-1
        else if item1.SubItems.Strings[num-1]=item2.SubItems.Strings[num-1] then compare:=0
        else compare:=1;
    end;
    end;
    procedure TForm1.Button4Click(Sender: TObject);
    var
       i:integer;
    begin
    for i:=1 to l.Items.Count do l.Items.Item[i-1].StateIndex:=0;
    l.ViewStyle :=vsicon;
    end;procedure TForm1.Button5Click(Sender: TObject);
    var
       i:integer;
    begin
    for i:=1 to l.Items.Count do l.Items.Item[i-1].StateIndex:=-1;
    l.ViewStyle :=vslist;
    end;procedure TForm1.Button6Click(Sender: TObject);
    var
       i:integer;
    begin
    for i:=1 to l.Items.Count do l.Items.Item[i-1].StateIndex:=-1;
    l.ViewStyle :=vsreport;
    end;procedure TForm1.Button7Click(Sender: TObject);
    var
       i:integer;
    begin
    for i:=1 to l.Items.Count do l.Items.Item[i-1].StateIndex:=-1;
    l.ViewStyle :=vssmallicon;
    end;end.