就是用stringgrid读取一个文本文件,文本文件内容为
张三 98.3  foo foo foo
李四 100   foo foo foo
王五 99    foo foo foo显示到stringgrid中时按数值(即成绩)由大到小排序:姓名 成绩   列3  列4  列5
李四 100    foo  foo  foo
王五 99     foo  foo  foo
张三 98.3   foo  foo  foo

解决方案 »

  1.   

    可以首先将文件内容读取到一个TStringList中,然后利用TStringList.CustomSort方法按照你的要求排序,最后再写入StringGrid————————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    ————————————————————————————————————
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      StrList: TStrings;
      KeyArray: Array of Double;
      temp: Double;
      Changed: Boolean;
      I,J: Integer;
      function GetKey(str: string): Double;
      var
        P: Integer;
      const
        SepStr = #9;
      begin
        Result := 0;
        P := AnsiPos(SepStr, str);
        if P > 0 then
        begin
          Delete(str, 1, P);
          P := AnsiPos(SepStr, str);
          if P > 0 then
            Result := StrToFloatDef(Copy(str, 1, P-1), 0);
        end;
      end;
    begin
      StrList := TStringList.Create;
      StrList.LoadFromFile('g:\a.txt');
      SetLength(KeyArray, StrList.Count);
      for I := 0 to StrList.Count-1 do
        KeyArray[I] := GetKey(StrList[I]);
      StrList.BeginUpdate;
      Changed := False;
      for I := StrList.Count-1 downto 0 do
      begin
        for J := 0 to I-1 do
        begin
          if KeyArray[J] > KeyArray[J+1] then
          begin
            temp := KeyArray[J];
            KeyArray[J] := KeyArray[J+1];
            KeyArray[J+1] := temp;
            StrList.Exchange(J, J+1);
            Changed := True;
          end;
        end;
        if not Changed then Break;
      end;
      StrList.EndUpdate;
      StrList.SaveToFile('g:\aa.txt');  //此时的StrList中包含了排序后的内容
      StrList.Free;
    end;————————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    ————————————————————————————————————
      

  3.   

    GetKey是一个字过程,取得98.3  99 100等值————————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    ————————————————————————————————————
      

  4.   

    你换个listview ,有排序方法,可以根据列排序;或者是你写入到stringgrid之前就排序一次呀